Test instructions: give you n the course group, each course group has m courses, each course has a completion time and value. Ask for a maximum of one per group of course groups within m days, so what is the maximum value you can get?
Puzzle: Group backpack, in fact, each course group to carry out 01 backpacks, and then in the course group to enumerate the course, but here must put the enumeration course in the innermost layer to ensure that the most select a
#include <Set>#include<map>#include<queue>#include<stack>#include<cmath>#include<vector>#include<string>#include<cstdio>#include<cstring>#include<iomanip>#include<stdlib.h>#include<iostream>#include<algorithm>using namespacestd;#defineEPS 1E-8/*Note that there may be output -0.000*/#defineSGN (x) (X<-eps -1:x<eps? 0:1)//X is a comparison of two floating-point numbers, note the return integer#defineCvs (x) (x > 0.0 x+eps:x-eps)//floating point Conversion#defineZero (x) (((x) >0? ( x):-(x)) <eps)//determine if it equals 0#defineMul (A, B) (a<<b)#defineDir (A, B) (a>>b)typedefLong Longll;typedef unsignedLong Longull;Const intinf=1<< -;Constll inf=1ll<< -;Const DoublePi=acos (-1.0);Const intmod=1e9+7;Const intmax= the; ll Val[max][max],dp[max];ll DP (intNintm) {ll Manx=-INF; for(intI=1; i<=m;++i) dp[i]=-INF; dp[0]=0LL; for(intI=1; i<=n;++i)//divided into n groups { for(intJ=M;J;--J)//first enumerate the total value { for(intk=1; k<=j;++k)//then enumerate each set of internal{Dp[j]=max (dp[j],dp[j-k]+Val[i][k]); Manx=Max (manx,dp[j]); } } } returnManx;}intMain () {//Std::ios::sync_with_stdio (false); intn,m; while(~SCANF ("%d%d", &n,&m) && (n| |m)) { for(intI=1; i<=n;++i) { for(intj=1; j<=m;++j) {scanf ("%i64d",&Val[i][j]); }} printf ("%i64d\n", Dp (n,m)); } return 0;}
HDU 1712 Acboy needs your help (group backpack)