Test instructions: CF-like format, each topic has a a,b,c three values, a for the initial score, B indicates that the score per minute will be reduced b,c indicates that the problem requires C minutes, the data guarantee score will not become negative. Now give the game length, ask to arrange the order of the questions, to find the maximum score.
Idea: This problem is a very classic problem. First, it is easy to think of one thing, given the question which first do not order, then in the dynamic planning, there must be a sequence, so either the state compression, or before the problem is sorted, so that the latter is orderly. The pressure is not considered because the data is too large, so we consider how to sort.
Now there are A1,B1,C1 and a2,b2,c2 these two questions, if first do 1 again do 2 of the score is a1-b1*c1+a2-b2* (C1+C2), if first do 2 in doing 1 of the score is a2-b2*c2+a1-b1* (C1+C2), so that first do 1 again do 2 score higher, Then there is a1-b1*c1+a2-b2* (C1+C2) >= a2-b2*c2+a1-b1* (C1+C2), Solution b1*c2>=b2*c1
So, as long as the B1*C2>=B2*C1, then the first 1 to do the title 2 of the score will be higher.
So, we just need to sort by this, and then DP, we can get the answer.
1 #pragmaComment (linker, "/stack:1024000000,1024000000")2#include <iostream>3#include <cstdio>4#include <cstring>5#include <cmath>6#include <math.h>7#include <algorithm>8#include <queue>9#include <Set>Ten#include <bitset> One#include <map> A#include <vector> -#include <stdlib.h> -#include <stack> the using namespacestd; - #definePI ACOs (-1.0) - #defineMax (a) (a) > (b)? (a): (b) - #defineMin (a) (a) < (b)? (a): (b) + #definell Long Long - #defineEPS 1e-10 + #defineMOD 1000000007 A #defineN 1006 at #defineM 5006 - #defineINF 1<<26 - intn,m; - structnode{ - inta,b,c; - BOOL operator< (ConstNode &x)Const{ in return(LL) b*x.c> (LL) x.b*C; - } to }node[n]; + intDp[m]; - intMain () the { * intT; $scanf"%d",&t);Panax Notoginseng while(t--){ -scanf"%d%d",&n,&m); the for(intI=1; i<=n;i++){ +scanf"%d%d%d",&node[i].a,&node[i].b,&node[i].c); A } theSort (node+1, node+n+1); + -Memset (DP,0,sizeof(DP)); $ for(intI=1; i<=n;i++){ $ for(intj=m;j>=node[i].c;j--){ -Dp[j]=max (dp[j],dp[j-node[i].c]+ (node[i].a-node[i].b*j)); - } the } - Wuyi intans=0; the for(intI=0; i<=m;i++){ -ans=Max (ans,dp[i]); Wu } -printf"%d\n", ans); About } $ return 0; -}
View Code
Hdu 5501 the highest Mark (greedy +01 backpack)