Dfs.
1 /*1539*/2#include <iostream>3#include <cstdio>4#include <cstring>5#include <cstdlib>6#include <vector>7 using namespacestd;8 9 #defineINF 0XFFFFFFFTen One intq[ the]; A Chars[ -]; - intans; - intT, Len; the BOOLFlag; -vector<int>TB; - - voidDfsintBegintSumintN) { + intI, J, K, TMP; - + if(Beg = =Len) { A if(Sum<=t && sum>ans) { at tb.clear (); - for(i=0; i<n; ++i) - Tb.push_back (Q[i]); -Ans =sum; -Flag =false; -n =0; in}Else if(Sum = =ans) { -Flag =true; to } + return ; - } the * for(I=beg; i<len; + +)i) { $TMP =0;Panax Notoginseng for(J=beg; j<=i; + +)j) -TMP =Ten*tmp+s[j]-'0'; theQ[n] =tmp; +DFS (i+1, Sum+tmp, n+1); A } the } + - intMain () { $ intI, J, K, TMP; $ intsum; - - #ifndef Online_judge theFreopen ("data.in","R", stdin); - #endifWuyi the while(SCANF ("%d%s", &t, s)! =EOF) { - if(t==0&& s[0]=='0'&& s[1]==' /') Wu Break; -sum =0; AboutTMP =0; $ for(i=0; S[i]; ++i) { -TMP =Ten*tmp+s[i]-'0'; -Sum + = s[i]-'0'; - } ALen =i; + if(Sum >t) { theprintf"error\n"); - Continue; $ } the if(TMP = =t) { theprintf"%d%s\n", T, s); the Continue; the } -Flag =false; inAns =-1; the tb.clear (); theDfs0,0,0); About if(flag) { theprintf"rejected\n"); the}Else { theprintf"%d", ans); + for(i=0; I<tb.size (); ++i) -printf"%d", Tb[i]); theprintf"\ n");Bayi } the } the - return 0; -}
"Hdoj" 1539 shredding Company