하다보니
15652번-n과 m(4) 본문
/*
n까지 자연수 중 m개를 고른 수열
같은 수를 여러 번 골라도 된다.
같은 수를 골라도 되고 비내림차순이어야 한다.
*/
#include<iostream>
using namespace std;
int n, m;
int arr[10];
void func(int k) {
if (k == m) {
for (int i = 0; i < m; i++) {
cout << arr[i]<<' ';
}
cout << "\n";
return;
}
int st = 1;
if (k != 0)st = arr[k - 1];
for (int i = st; i <=n; i++) {
arr[k] = i;
func(k + 1);
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
func(0);
}
'알고리즘 풀이 > 백준' 카테고리의 다른 글
15655번-n과 m(6) (0) | 2022.03.09 |
---|---|
15654번-n과 m(5) (0) | 2022.03.08 |
15651번-n과 m(3) (0) | 2022.03.08 |
15650번-n과 m (2) (0) | 2022.03.08 |
1182번-부분수열의 합 (0) | 2022.03.08 |