#include <stdio.h>#include <string.h>#include <algorithm>using namespace STD;intn,m,p[ -+5],h[ -+5],c[ -+5],dp[ -+5];voidZeroonepack (intCostintWeight) { for(inti=n;i>=cost;i--) {Dp[i]=max (dp[i],dp[i-cost]+weight); }}voidCompletepack (intCostintWeight) { for(inti=cost;i<=n;i++) {Dp[i]=max (dp[i],dp[i-cost]+weight); }}voidMultiplepack (intCostintWeightintAmount) {if(amount*cost>=n) Completepack (cost,weight);Else{intk=1; while(K<amount) {Zeroonepack (cost*k,weight*k); Amount-=k; k*=2; } zeroonepack (Cost*amount,weight*amount); }}intMain () {int_,i,j;scanf("%d", &_); while(_--) {scanf("%d%d", &n,&m); for(i=0; i<m;i++)scanf("%d%d%d", &p[i],&h[i],&c[i]);memset(DP,0,sizeof(DP)); for(i=0; i<m;i++) {#include <stdio.h>#include <string.h>#include <algorithm>using namespace STD;intn,m,p[ -+5],h[ -+5],c[ -+5],dp[ -+5];voidZeroonepack (intCostintWeight) { for(inti=n;i>=cost;i--) {Dp[i]=max (dp[i],dp[i-cost]+weight); }}voidCompletepack (intCostintWeight) { for(inti=cost;i<=n;i++) {Dp[i]=max (dp[i],dp[i-cost]+weight); }}voidMultiplepack (intCostintWeightintAmount) {if(amount*cost>=n) Completepack (cost,weight);Else{intk=1; while(K<amount) {Zeroonepack (cost*k,weight*k); Amount-=k; k*=2; } zeroonepack (Cost*amount,weight*amount); }}intMain () {int_,i,j;scanf("%d", &_); while(_--) {scanf("%d%d", &n,&m); for(i=0; i<m;i++)scanf("%d%d%d", &p[i],&h[i],&c[i]);memset(DP,0,sizeof(DP)); for(i=0; i<m;i++) {multiplepack (p[i],h[i],c[i]); }printf("%d\n", Dp[n]); }return 0;} Multiplepack (P[i],h[i],c[i]); }printf("%d\n", Dp[n]); }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 2191 Mourning 512 Wenchuan earthquake--cherish now, Thanksgiving life