Notice
Recent Posts
Recent Comments
Link
«   2026/06   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Archives
Today
Total
관리 메뉴

dh-winternagi 님의 블로그

(15650) N과 M (2) 본문

백준 (C++)/Solve

(15650) N과 M (2)

dh-winternagi 2026. 4. 17. 08:12

https://www.acmicpc.net/problem/15650

단계별로 풀어보기

20단계(백트래킹) 2번째

 

 

 

#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]+1;i<=n;i++){
      v[depth]= i;
      self(self, depth+1);
    }
  };
  
  func(func, 0);
  
  return 0;
}

'백준 (C++) > Solve' 카테고리의 다른 글

(15652) N과 M (4)  (0) 2026.04.17
(15651) N과 M (3)  (0) 2026.04.17
(15649) N과 M (1)  (0) 2026.04.17
(11729) 하노이 탑 이동 순서  (0) 2026.04.17
(2447) 별 찍기 - 10  (0) 2026.04.17