标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 691 Accepted Submission(s): 450
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 using namespace std; 5 long long n,cnt,num; 6 int vis[20]; 7 char s[20]; 8 int len; 9 void dfs(int p,int num) 10 { 11 if(p==len) 12 {if(num==n) 13 { 14 cnt++; 15 return; 16 }} 17 long long temp=0; 18 for(int i=p;i<len;i++)//难点 19 { 20 temp=temp*10+(s[i]-‘0‘); 21 dfs(i+1,num+temp); 22 if(p!=0) 23 dfs(i+1,num-temp); 24 } 25 } 26 int main() 27 { 28 while(~scanf("%s%lld",s,&n)) 29 { 30 len=strlen(s); 31 cnt=0; 32 //temp=0; 33 dfs(0,0); 34 printf("%d\n",cnt); 35 } 36 return 0; 37 }
hdu 2266 How Many Equations Can You Find(DFS)
标签:
原文地址:http://www.cnblogs.com/ZP-Better/p/4650851.html