Swun 1388 your backpack.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.