标签:des style blog http color io os java ar
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 572 Accepted Submission(s): 228
1 //#define LOCAL 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 const int maxn=1002; 6 int aa[maxn],bb[maxn],cc[maxn<<1]; 7 int mat[maxn][maxn]; 8 int n1,n2; 9 bool flag; 10 void dfs(int lena,int lenb,int lenc) 11 { 12 if(lena==n1+1&&lenb==n2+1){ 13 flag=1; 14 return ; 15 } 16 if(mat[lena][lenb]) return ; 17 if(!flag&&aa[lena]==cc[lenc]){ 18 mat[lena][lenb]=1; 19 dfs(lena+1,lenb,lenc+1); 20 } 21 if(!flag&&bb[lenb]==cc[lenc]){ 22 mat[lena][lenb]=1; 23 dfs(lena,lenb+1,lenc+1); 24 } 25 } 26 void input(int n,int a[]) 27 { 28 for(int i=1;i<=n;i++) 29 scanf("%d",&a[i]); 30 } 31 int main() 32 { 33 #ifdef LOCAL 34 freopen("test.in","r",stdin); 35 #endif 36 while(scanf("%d%d",&n1,&n2)&&n1+n2!=0) 37 { 38 input(n1,aa); 39 aa[n1+1]=-1; 40 input(n2,bb); 41 bb[n2+1]=-1; 42 input(n1+n2,cc); 43 flag=0; 44 memset(mat,0,sizeof(mat)); 45 dfs(1,1,1); 46 if(flag)printf("possible\n"); 47 else printf("not possible\n"); 48 } 49 return 0; 50 }
hdu---(3779)Railroad(记忆化搜索/dfs)
标签:des style blog http color io os java ar
原文地址:http://www.cnblogs.com/gongxijun/p/3993447.html