Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
我泪流满面 等于八皇后怎么会出不来In Reply To:等于八皇后 Posted by:vince4053040 at 2010-02-20 20:10:06 #include<iostream> #include<string> #include<cstdio> using namespace std; char map[8][8]; bool visit_R[8]; bool visit_C[8]; int k, sum, N; void dfs(int i) { int j; for(j = 0; j < N; j ++) { if(i >= 0 && i < N && map[i][j] == '#' && visit_C[j] == 0 && visit_R[i] == 0) { visit_R[i] = 1; visit_C[j] = 1; map[i][j] = '.'; if(i == k) sum ++; else dfs(i + 1); visit_R[i] = 0; //回溯 visit_C[j] = 0; map[i][j] = '#'; } } return ; } int main() { int i, j; while(cin >> N >> k && N != -1) { for(i = 0; i < N; i ++) for(j = 0; j < N; j ++) cin >> map[i][j]; memset(visit_R, 0, sizeof(visit_R)); memset(visit_C, 0, sizeof(visit_C)); sum = 0; dfs(0); cout << sum << endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator