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)