UVA 10465 Homer Simpson topic: There are two kinds of burgers, giving the time to eat each burger, and the total time. Find out the maximum number of hamburgers that can be eaten in full use of time. When all time is not available, the remaining time is output after the number of burgers. Solution: Complete backpack.
#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <cstdlib>typedef Long Longllusing namespace STD; ll dp[20005];intMain () {intnum[2], sum; while(scanf(" %d%d%d", &num[0], &num[1], &sum) = =3) {memset(DP,0,sizeof(DP)); dp[0] =1; for(inti =0; I <2; i++) { for(intj =0; J <= Sum; J + +) {if(Dp[j] && dp[j + num[i]] < DP[J] +1) {dp[j + num[i]] = Dp[j] +1; } } }intCNT =0; while(!dp[sum]) {sum--; cnt++; }printf("%lld", Dp[sum]-1);if(CNT)printf("%d", CNT);printf("\ n"); }return 0;}
UVA 10465 Homer Simpson (full backpack)