목록백트래킹 (4)
레야몬
#include #define LOOP(i, N) for(int i=1; i> matmp[i][j]; ma[i][j]=matmp[i][j] - '0'; int v = ma[i][j]; col[j][v]=row[i][v]=box[(i-1)/3*3 + (j-1)/3][v]=1; } } } void backtracking(int cnt) { if(cnt == 82) { //도착하면 출력 후 종료 LOOP(i, 9) { LOOP(j, 9) cout
#include #include #define MAX_N 9 using namespace std; bool visit[MAX_N]; //방문하였는가? int map[MAX_N]; //입력받은 숫자들 int b[MAX_N]; //탐색한 숫자가 저장되는 벡터 int N, M; //N개의 자연수와 길이가 M인 수열 void f(int m) //m개를 저장함 { if(m==M) { for(int i=0; i map[i]; sort(map, map+N); //오름차순으로 정렬하기 f(0); return 0; } 백트래킹이 맞는 것 같네요. 문제를 풀고나니 왜 이게 백트래킹이지 싶었는데... 암튼 밑에 참고한 사이트가 있어요 https://blockdmask.tistory.com/70 [C++] vector con..
#include #include using namespace std; int N, M; //자연수 N, 길이가 M인 수열 void f(int n, int m, vector v) //현재 숫자와 몇 개 출력했음? { if(m==M) { //다 선택했으면 출력 for(int i=0; i