Summer Camp (5) second ——— the story of the series--weight Loss kee I (hdu4508)

Source: Internet
Author: User

Problem Description: Lick the grease on your mouth, and you're stuck on a soft settee behind your back. In the German source contest won the winning you, can't wait to "eat to full" restaurant to eat full. When you

Being ready to leave, the waiter called You, "Sir, you have not eaten the food you ordered." "Pointing to a mess on your desk, but there are still a lot of remnants of the" military "scene. You just pink your face and turned into a frost-beaten eggplant. Watching the food on the table is still worrying. "I can help you solve it." "You look to the side and find out that she is the source of the German competition

The contestants tweeted. It's not too late to say thank you. She offered the conditions for the energy , happiness, and maximum energy limits of the food, and how to limit the maximum energy levels

Maximum happiness in a given situation.

Problem analysis: Full knapsack problem, current status update if (previous happiness + new happiness) > Current happiness. And the energy does not exceed the maximum energy limit.

The state transition equation is dp[i] =max (Dp[i-power[i]] + power[i],dp[i]), where minus power[i] is to get the happiness before.

1#include"Cstdio"2 inthappy[ -];3 intoil[ -];4 intdp[100004];5 voidHbegin (intN)6 {7      for(intI=0; i<n;i++)8     {9scanf ("%d%d",&happy[i],&oil[i]);Ten     } One      for(intI=0;i<100004; i++) A     { -Dp[i] =0; -     } the } - intMaxintXinty) - { -     returnX>y?x:y; + } - intMain () + { A     intN,o; at      while(SCANF ("%d", &n)! =EOF) -     { - hbegin (n); -scanf ("%d",&o); -          for(intI=0; i<n;i++) -          { in              for(intj=oil[i];j<=o;j++) -             { toDP[J] = max (dp[j-oil[i]]+happy[i],dp[j]); +             } -          } theprintf ("%d\n", Dp[o]); *     } $     return 0;Panax Notoginseng}
View Code

Summer Camp (5) second ——— the story of the series--weight Loss kee I (hdu4508)

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.