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 |
大牛们帮我看看哪错了~菜鸟刚开始学递归~搜索#include <cstdio> #include <iostream> using namespace std; int result,n,k; char mp[10][10]; int visrow[10],viscol[10]; void dfs(int row,int leftchess) { int col; for (col=0;col<n;col++) { if (mp[row][col] == '#' && !visrow[row] && !viscol[col]) { visrow[row] = 1; viscol[col] = 1; leftchess--; if ((row + 1) < n && leftchess > 0) dfs(row + 1,leftchess); else if (leftchess == 0) result++; leftchess++; visrow[row] = 0; viscol[col] = 0; } } } int main() { int k,i,j; while (scanf("%d%d",&n,&k) != EOF) { getchar(); if (n + k == -2) return 0; for (i=0;i<n;i++) gets(mp[i]); memset(visrow,0,sizeof(visrow)); memset(viscol,0,sizeof(viscol)); result = 0; for (i=0;i<n;i++) dfs(i,k); printf("%d\n",result); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator