Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5938
Test instructions: Give a 2020 string of the maximum length, you want to divide the numbers into 55 segments, then fill in the ' + ', '-', ' * ', '/', and ask for the maximum result you can get.
To make this result the largest, as far as possible to let the number of the left side of the largest, only need to care about the left of the first bit is a number or the last one is a number, followed by the enumeration * and/the position of the line.
1#include <bits/stdc++.h>2 using namespacestd;3 4typedefLong LongLL;5 Const intMAXN = A;6 LL ret, Dret;7 intN;8 CharS[MAXN];9 Ten voidDfsintPosintCNT, LL C, LL D, ll E) { One if(POS >= N)return; A if(CNT = =3) { -Dret = min (Dret, c * d/e); - return; the } - if(CNT = =0) { -LL tmp =0; - for(inti = pos; I < n; i++) { +TMP *=Ten; TMP = tmp + s[i]-'0'; -DFS (i+1, cnt+1, tmp,d,e); + } A } at if(CNT = =1) { -LL tmp =0; - for(inti = pos; I < n; i++) { -TMP *=Ten; TMP = tmp + s[i]-'0'; -DFS (i+1, cnt+1, c,tmp,e); - } in - } to if(CNT = =2) { +LL tmp =0; - for(inti = pos; I < n; i++) { theTMP *=Ten; TMP = tmp + s[i]-'0'; * } $DFS (-1, cnt+1, c,d,tmp);Panax Notoginseng } - } the + intMain () { A //freopen ("in", "R", stdin); the intT, _ =1; +scanf"%d", &T); - while(t--) { $scanf"%s", s); $n =strlen (s); -ret =-(LL)1<< +); - for(inti =1; I < n3; i++) { theLL x =0; -LL y =0;WuyiLL S1 =0, S2 =0, SS =0; the intj =0; - while(J <i) { WuX *=Ten; -x = x + s[j++]-'0'; About } $y = s[i]-'0'; -S1 = x +y; -j =1; -x = s[0] -'0'; y =0; A while(J <=i) { +Y *=Ten; they = y + s[j++]-'0'; - } $S2 = x +y; theSS =Max (S1, S2); theDret = (LL)1<< +; theDFS (i+1,0,0,0,0); theRET = max (ret, ss-Dret); - } inprintf"Case #%d:", _++); theprintf"%i64d\n", ret); the } About return 0; the}
[HDOJ5938] Four Operations (violence, DFS)