Problem-solving ideas: The first response to the problem is the backpack, the second response is greedy, I use a search, enumeration can be, to have this consciousness,
Only 8 of the problem data, violence can be solved.
1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 Const intMAXN =Ten;6 intV[MAXN], VIS[MAXN];7 intva, vb, ans;8 9 voidDFS (intVaintVbintCNT)Ten { Oneans = max (ans, CNT);//ans records the largest CNT A for(inti =0; I <8; i++) - { - if(!vis[i])//used books are no longer available. the { -Vis[i] =1; - if(VA >= v[i]) DFS (Va-v[i], VB, CNT +1);//There's a recursive tree in my heart - if(VB >= v[i]) DFS (VA, vb-v[i], CNT +1); +Vis[i] =0;//This step must not be less, backtracking. - } + } A return ; at } - - intMain () - { - while(~SCANF ("%d%d", &va, &vb)) - { in for(inti =0; I <8; i++) scanf ("%d", &v[i]); -memset (Vis,0,sizeof(Vis)); toAns =0; + //sort (V, v + 8);//This step has no effect because the search enumerates all the cases. -DFS (VA, VB,0); theprintf"%d\n", ans); * } $ return 0;Panax Notoginseng}View Code
Swun 1388 your backpack.