| ||||||||||
| 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了,#include<iostream>
#include<algorithm>
using namespace std;
int value[8][8],i,j,n,m,ans;
bool usedx[8],usedy[8];
char ch;
void dfs(int x,int y,int su)
{
if(usedx[x]==1||usedy[y]==1)
return ;
if(x<0||x>=n||y<0||y>=n)
return ;
if(value[x][y]==0)
return ;
su++;
if(su==m)
{
ans++;
return ;
}
usedx[x]=usedy[y]=1;
for(i=x;i<n;i++)
for(j=0;j<n;j++)
dfs(i,j,su);
usedx[x]=usedy[y]=0;
}
int main()
{
while(cin>>n>>m)
{
if(n==-1&&m==-1)
break;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
cin>>ch;
if(ch=='.')
value[i][j]=0;
if(ch=='#')
value[i][j]=1;
}
ans=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(value[i][j]==1)
dfs(i,j,0);
}
cout<<ans<<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