dh-winternagi 님의 블로그
(15652) N과 M (4) 본문
https://www.acmicpc.net/problem/15652
단계별로 풀어보기
20단계(백트래킹) 4번째

#include <iostream>
#include <vector>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m;
cin >> n >> m;
vector<int> v(m);
auto func= [&](auto self, int depth) -> void {
if(depth==m){
for(int elem:v) cout << elem << " ";
cout << "\n";
return;
}
for(int i=depth==0?1:v[depth-1];i<=n;i++){
v[depth]= i;
self(self, depth+1);
}
};
func(func, 0);
return 0;
}'백준 (C++) > Solve' 카테고리의 다른 글
| (2580) 스도쿠 (0) | 2026.04.17 |
|---|---|
| (9663) N-Queen (0) | 2026.04.17 |
| (15651) N과 M (3) (0) | 2026.04.17 |
| (15650) N과 M (2) (0) | 2026.04.17 |
| (15649) N과 M (1) (0) | 2026.04.17 |
