1#include <cstdio>2#include <cstring>3 using namespacestd;4 intmmax,sum;5 Chars[Ten];6 BOOLv[Ten],way[Ten];7 BOOLrejected;8 voidDfsintDepintValueintbefore)9 {Ten intnow=0; One for(inti=before;i<dep;i++) A { -now=now*Ten; -now=now+s[i]-'0'; the } - if(dep==strlen (s)) - { - intAns=value+Now ; + if(Ans>mmax)return; - if(ans==sum) + { ARejected=true; at return; - } - Else if(ans>sum) - { -sum=ans; -Rejected=false; in for(intI=0; I<strlen (s); i++) way[i]=V[i]; - return; to } + return; - } the if(Value>mmax)return; *v[dep]=1; $DFS (dep+1, value+NOW,DEP);Panax Notoginsengv[dep]=0; -DFS (dep+1, Value,before); the + } A intMain () the { +scanf"%d%s",&mmax,s); - while(mmax!=0) $ { $memset (V,0,sizeof(v)); -sum=0; -v[0]=1; theRejected=false; -Dfs1,0,0);Wuyi if(rejected==true) printf ("rejected\n"); the Else if(sum==0) printf ("error\n"); - Else Wu { -printf"%d", sum); About for(intI=0; I<strlen (s); i++) $ { - if(way[i]==1) printf (" "); -printf"%c", S[i]); - } Aprintf"\ n"); + } thescanf"%d%s",&mmax,s); - } $ return 0; the}
Dfs/poj 1416 Shredding Company