서의 공간

[백준] 15652_N과 M (4) 본문

Algorithm/백준

[백준] 15652_N과 M (4)

홍서의 2021. 2. 6. 04:24

[문제]: 15652번: N과 M (4) (acmicpc.net)

 

#include <iostream>
using namespace std;

int n, m;
int arr[10];

void solution(int k, int p)
{
	if (k == m) {
		for (int i = 0; i < m; ++i)
			cout << arr[i] << ' ';
		cout << '\n';
		return;
	}

	for (int i = p; i <= n; ++i) {
		arr[k] = i;
		solution(k + 1, i);
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cin >> n >> m;
	solution(0, 1);
	return 0;
}

'Algorithm > 백준' 카테고리의 다른 글

[백준] 15655_N과 M (6)  (0) 2021.02.06
[백준] 15654_N과 M (5)  (0) 2021.02.06
[백준] 15651_N과 M (3)  (0) 2021.02.06
[백준] 15650_N과 M (2)  (0) 2021.02.06
[백준] 15649_N과 M (1)  (0) 2021.02.06
Comments