After the competition, I was told that it was a DFS question. I had the place where I enumerated =. Then I checked whether the results on both sides were the same, each position on both sides of the equal sign is either placed with + or not. In addition, because 1 + 11 = 12 and 11 + 1 = 12 are two types in the question, you cannot save only the result 12 on the left of the equal sign, but also the number of 12, I saved it directly using a vector, and added 1 if the scanning surface has the same content. this DFS was written for two or three hours,CodeThe capability is still too bad.
# Include <iostream> # include <cstdio> # include <cstdlib> # include <vector> # include <cmath> # include <set> # include <cstring> # include <algorithm> # define maxn 500010 using namespace STD; char STR [20]; bool save [20]; int ans, I; set <int> ST1; vector <int> st; void DFS (INT cur, int end, int sum) {If (cur = END) {int temp = cur; while (save [temp] = false & temp> = 0) temp --; int num = 0; For (Int J = ++ temp; j <= cur; j ++) num = num * 10 + STR [J]-'0 '; Sum + = num; ST. push_back (SUM); return;} Save [cur] = true; int num = 0; int temp = cur-1; while (save [temp] = false & temp> = 0) temp --; For (Int J = ++ temp; j <= cur; j ++) num = num * 10 + STR [J]-'0'; sum + = num; DFS (cur + 1, end, sum); save [cur] = false; sum-= num; DFS (cur + 1, end, sum);} void dfs2 (INT cur, int end, int sum) {If (cur = end) {int temp = cur; while (save [temp] = false & temp> I) temp --; int num = 0; For (Int J = ++ temp; j <= cur; J ++) num = num * 10 + STR [J]-'0'; sum + = num; For (Int J = 0; j <(INT) ST. size (); j ++) {If (sum = sT [J]) ans ++;} return;} Save [cur] = true; int num = 0; int temp = cur-1; while (save [temp] = false & temp> I) temp --; For (Int J = ++ temp; j <= cur; j ++) num = num * 10 + STR [J]-'0'; sum + = num; dfs2 (cur + 1, end, sum ); save [cur] = false; sum-= num; dfs2 (cur + 1, end, sum);} int main () {// freopen ("in.txt ", "r", stdin); While (CIN> STR & strcmp (STR, "End ")! = 0) {int Len = strlen (STR); ans = 0; for (I = 0; STR [I + 1]! = '\ 0'; I ++) {St. clear (); memset (save, false, sizeof (SAVE); DFS (0, I, 0); dfs2 (I + 1, len-1, 0 );} cout <ans <Endl;} return 0 ;}