标签:++ process ima its == cond color miss alternate
3 3 1 2 1 2 1 1 1 2 1 1 2 1 3 3 1 2 1 2 1 2 1 1 1 2 2 2 0 0
possible not possible
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n,m; int a[1005],b[1005],c[2010]; bool vis[1005][1005]; bool dfs(int x,int y,int k) { if (k==n+m+1) return 1; if(vis[x][y]) return 0; vis[x][y]=1; if (x<=n && a[x]==c[k] && dfs(x+1,y,k+1)) return 1; if (y<=m && b[y]==c[k] && dfs(x,y+1,k+1)) return 1; return 0; } int main() { while(~scanf("%d%d",&n,&m)) { if (n==0 && m==0) break; for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=m;i++) scanf("%d",&b[i]); for(int i=1;i<=n+m;i++)scanf("%d",&c[i]); memset(vis,0,sizeof(vis)); if (dfs(1,1,1)) printf("possible\n"); else printf("not possible\n"); } return 0; }
标签:++ process ima its == cond color miss alternate
原文地址:http://www.cnblogs.com/stepping/p/7181902.html