标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
//1085422276 #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<queue> #include<cmath> #include<map> #include<bitset> #include<set> #include<vector> using namespace std ; typedef long long ll; #define mem(a) memset(a,0,sizeof(a)) #define meminf(a) memset(a,127,sizeof(a)); #define memfy(a) memset(a,-1,sizeof(a)) #define TS printf("111111\n"); #define FOR(i,a,b) for( int i=a;i<=b;i++) #define FORJ(i,a,b) for(int i=a;i>=b;i--) #define READ(a,b,c) scanf("%d%d%d",&a,&b,&c) #define mod 1000000007 #define maxn 106 inline ll read() { ll x=0,f=1; char ch=getchar(); while(ch<‘0‘||ch>‘9‘) { if(ch==‘-‘)f=-1; ch=getchar(); } while(ch>=‘0‘&&ch<=‘9‘) { x=x*10+ch-‘0‘; ch=getchar(); } return x*f; } //**************************************** int n,m,ans,fsum; vector<int >G[5]; char a[41]; void dfs1(int x,int right,int sum,int last) { if(x==right) { if(!last) G[1].push_back(sum+last); return ; } dfs1(x+1,right,sum+last*10+a[x],0);///f dfs1(x+1,right,sum,last*10+a[x]); } void dfs2(int x,int right,int sum,int last) { if(x==right) {if(!last) G[2].push_back(sum+last); return ; } dfs2(x+1,right,sum+last*10+a[x],0);///f dfs2(x+1,right,sum,last*10+a[x]); } int main() { while(scanf("%s",a)!=EOF) { ans=0; if(strcmp(a,"END")==0) break; n=strlen(a); FOR(i,0,n-1)a[i]=a[i]-‘0‘; FOR(i,1,n-1) { G[1].clear();G[2].clear(); if(i==1) G[1].push_back(a[0]); else dfs1(0,i,0,0); if(i==n-1) G[2].push_back(a[i]); else dfs2(i,n,0,0); for(int j=0;j<G[1].size();j++) for(int k=0;k<G[2].size();k++) { if(G[1][j]==G[2][k])ans++; } } cout<<ans<<endl; ///getchar(); } return 0; }
HDU4403 A very hard Aoshu problem DFS
标签:
原文地址:http://www.cnblogs.com/zxhl/p/4808332.html