标签:i++ char each asc into open term eve tip
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 119601 Accepted Submission(s): 32313
1 #include<iostream> 2 3 using namespace std; 4 5 int n,m,t,di,dj; 6 char num[9][9]; 7 bool escape; 8 int dir[4][2]={{0,-1},{0,1},{1,0},{-1,0}}; 9 10 void dfs(int si,int sj,int cnt) 11 { 12 int i,temp; 13 if(si>n || sj>m || si<=0 || sj<=0) 14 return ; 15 if(cnt==t && si==di && sj==dj) 16 escape=1; 17 if(escape) 18 return ; 19 //奇偶剪枝 20 temp = (t-cnt)-abs(si-di)-abs(sj-dj); 21 if(temp<0 || temp&1) 22 return ; 23 24 for(i=0;i<4;i++) 25 { 26 if(num[si+dir[i][0]][sj+dir[i][1]]!=‘X‘) 27 { 28 num[si+dir[i][0]][sj+dir[i][1]]=‘X‘; 29 dfs(si+dir[i][0],sj+dir[i][1],cnt+1); 30 num[si+dir[i][0]][sj+dir[i][1]]=‘.‘; 31 } 32 } 33 return ; 34 } 35 int main() 36 { 37 int i,j,si,sj; 38 while(cin>>n>>m>>t,n||m||t) 39 { 40 int wall = 0; 41 for(i=1;i<=n;i++) 42 for(j=1;j<=m;j++) 43 { 44 cin>>num[i][j]; 45 if(num[i][j]==‘S‘) 46 si=i,sj=j; 47 else 48 if(num[i][j]==‘D‘) 49 di=i,dj=j; 50 else 51 if(num[i][j]==‘X‘) 52 wall++; 53 } 54 if(n*m-wall<=t) 55 { 56 cout<<"NO"<<endl; 57 continue; 58 } 59 escape=0; 60 num[si][sj]=‘X‘; 61 dfs(si,sj,0); 62 if(escape) 63 cout<<"YES"<<endl; 64 else 65 cout<<"NO"<<endl; 66 } 67 return 0; 68 }
标签:i++ char each asc into open term eve tip
原文地址:http://www.cnblogs.com/Xycdada/p/6713586.html