hdu3602 (deformed backpack)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.