Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

forget backtrack?

Posted by lxc0601 at 2008-05-15 19:50:50 on Problem 1154
In Reply To:这也有错,晕啊! Posted by:ylshtfa at 2007-12-26 22:28:37
> #include<iostream>
> using namespace std;
> char a[23][23];
> int large=0;
> void DFS(int i,int j,int counter,bool c[],bool visit[][23])
> {
>     if(!c[a[i][j]-'A'+1])
>         c[a[i][j]-'A'+1]=true;
>     if(counter>large)
>         large=counter;  
>     if(counter>large)
>            large=counter;
>     if(!visit[i+1][j] && !c[a[i+1][j]-'A'+1] && a[i+1][j]>='A' && a[i+1][j]<='Z')
>            DFS(i+1,j,counter+1,c,visit);
>     if(!visit[i-1][j] && !c[a[i-1][j]-'A'+1] && a[i-1][j]>='A' && a[i-1][j]<='Z')
>            DFS(i-1,j,counter+1,c,visit);
>     if(!visit[i][j+1] && !c[a[i][j+1]-'A'+1] && a[i][j+1]>='A' && a[i][j+1]<='Z')
>            DFS(i,j+1,counter+1,c,visit);
>     if(!visit[i][j-1] && !c[a[i][j-1]-'A'+1] && a[i][j-1]>='A' && a[i][j-1]<='Z')
>            DFS(i,j-1,counter+1,c,visit);
>     return;
> }           
> int main()
> {
>     int r,s;
>     bool visit[23][23];
>     bool c[27];
>     memset(c,false,sizeof(c));
>     
>     scanf("%d %d",&r,&s);
>     while(getchar()!='\n');
>     for(int i=0;i<=21;i++)
>             for(int j=0;j<=21;j++)
>             {
>                     a[i][j]=0;
>                     visit[i][j]=true;
>             }//init
>     for(int i=1;i<=r;i++)
>     {
>             for(int j=1;j<=s;j++)
>             {
>                     scanf("%c",&a[i][j]);
>                     visit[i][j]=false;
>             }
>             while(getchar()!='\n');
>     }
>     DFS(1,1,1,c,visit);
>     printf("%d\n",large);
>     system("pause");
>     return 0;
> }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator