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 |
求解~兄弟们的样例我都测试过了 就是WA!!帮我看看 这不知杯具到哪了...每次range标记一行中一个#,没有在同列的 ,并dfs下一行 #include <iostream> #include <string> using namespace std; int cnt = 0; void dfs(string* grid, int& n, int k, int i, int range) { if (!k) { cnt++; return; } if (i == n) return; for(int j = 0; j < n; ++j) if (grid[i][j] == '#' && !((1 << j) & range)) dfs(grid, n, k - 1, i + 1, (1 << j) | range); } void calc(string* grid, int& n, int& k) { for(int i = 0; i < n; ++i) for(int j = 0; j < n; ++j) { if (grid[i][j] == '#') { int range = 1 << j; dfs(grid, n, k - 1, i + 1, range); for(int t = i + 2; t < n; ++t) dfs(grid, n, k - 1, t, range); } } } int main() { int n, k; while(scanf("%d%d", &n, &k) , n != -1 && k != -1) { string *grid = new string[n]; for(int i = 0; i < n; ++i) cin >> grid[i]; cnt = 0; calc(grid, n, k); cout << cnt << endl; delete[] grid; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator