zoukankan      html  css  js  c++  java
  • HDU3466背包01

    Proud Merchants

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
    Total Submission(s): 3126    Accepted Submission(s): 1288


    Problem Description
    Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerful kingdom in the world. As a result, the people in this country are still very proud even if their nation hasn’t been so wealthy any more.
    The merchants were the most typical, each of them only sold exactly one item, the price was Pi, but they would refuse to make a trade with you if your money were less than Qi, and iSea evaluated every item a value Vi.
    If he had M units of money, what’s the maximum value iSea could get?

     

     

    Input
    There are several test cases in the input.

    Each test case begin with two integers N, M (1 ≤ N ≤ 500, 1 ≤ M ≤ 5000), indicating the items’ number and the initial money.
    Then N lines follow, each line contains three numbers Pi, Qi and Vi (1 ≤ Pi ≤ Qi ≤ 100, 1 ≤ Vi ≤ 1000), their meaning is in the description.

    The input terminates by end of file marker.

     

     

    Output
    For each test case, output one integer, indicating maximum value iSea could get.

     

     

    Sample Input
    2 10 10 15 10 5 10 5 3 10 5 10 5 3 5 6 2 7 3
     

     

    Sample Output
    5 11
     
     
     
     
     
     
     
     
     
    #include<stdio.h>
    #include<string.h>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    int dp[5005];
    int p[505],q[505],c[505];
    int n,m;
    int pd1(int p[],int q[],int c[])
    {
        int temp;
        for(int i=1;i<=n-1;i++)
            for(int j=i+1;j<=n;j++)
        {
            if(q[i]-p[i]>q[j]-p[j])
            {
                temp=p[i];
                p[i]=p[j];
                p[j]=temp;
                temp=q[i];
                q[i]=q[j];
                q[j]=temp;
                temp=c[i];
                c[i]=c[j];
                c[j]=temp;
            }
        }
    }
    int main()
    {
        while(scanf("%d%d",&n,&m)!=EOF)
        {
            memset(p,0,sizeof(p));
            memset(q,0,sizeof(q));
            memset(c,0,sizeof(c));
            memset(dp,0,sizeof(dp));
            for(int k=1;k<=n;k++)
                scanf("%d%d%d",&p[k],&q[k],&c[k]);
                pd1(p,q,c);
                for(int i=1;i<=n;i++)
                  for(int j=m;j>=q[i];j--)
                    dp[j]=max(dp[j],dp[j-p[i]]+c[i]);
                  printf("%d ",dp[m]);
        }
        return 0;
    }
  • 相关阅读:
    Git学习手记(一)
    微信开发手记(二)
    mysql命令行打开中文乱码
    在linux上centos6安装pdo_mysql扩展
    在linux上安装php5.6版本提示GD2版本要高于2.1.0解决
    在linux上安装apache是出现error1错误
    在linux上搭建amp环境安装jpeg时出现libtool command not found,error127解决
    在linux中搭建amp环境(apache2.4.7+mysql5.5.23+php5.6.19)
    mysql忘记root密码解决办法
    移动端网页设计经验与心得
  • 原文地址:https://www.cnblogs.com/13224ACMer/p/4409493.html
Copyright © 2011-2022 走看看