Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=3602
Test instructions is: n countries, M spacecraft, each country has the number of NUM, if the spacecraft on the United Nations value money, the election of some countries to the ship and everyone in each country must be on the same boat, so that the United Nations to make the most money, and the selected countries to ship the order must be in line with the original country order.
Analysis: Dp[m][k] indicates that the maximum value of the capacity K is used for the ship of article M, O (NMK) algorithm is not feasible
Variant: Dp[i] represents the minimum cost to get the value I (The used position)
#include <cstdio>#include<cstring>#include<cmath>#include<iostream>#include<algorithm>#include<queue>#include<cstdlib>#include<vector>#include<Set>#include<map>#defineLL Long Long#defineMoD 1000000007#defineINF 0x3f3f3f3f#defineN 10010using namespacestd;intt,n,m,k;intDp[n];intCalintXinty) { intNum=ceil (x*1.0/k); if(X+y<=num*k)returnx+y; //The remaining amount is k-y, because the front of the ship no matter how many of the position, the back of the people can not reverse up the Else returnnum*k+y;}intMain () {scanf ("%d",&t); while(t--) {scanf ("%d%d%d",&n,&m,&k); Memset (DP,0x3f,sizeof(DP)); dp[0]=0; for(intI=1; i<=n;i++) { intb; scanf ("%d%d", &a,&b); a++; for(intI=10000; i>=b;i--) { if(dp[i-b]!=inf) dp[i]=min (Dp[i],cal (dp[i-b],a)); } } intans; for(intI=10000;; i--) { if(dp[i]<=m*k) {ans=i; Break; }} printf ("%d\n", ans); }}
View Code
hdu3602 (deformed backpack)