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\n",dp[m]);
    }
    return 0;
}

HDU3466背包01的更多相关文章

  1. BZOJ_4753_[Jsoi2016]最佳团体_树形背包+01分数规划

    BZOJ_4753_[Jsoi2016]最佳团体_树形背包+01分数规划 Description JSOI信息学代表队一共有N名候选人,这些候选人从1到N编号.方便起见,JYY的编号是0号.每个候选人 ...

  2. HDU--3466(0-1背包+贪心/后效性)

    题意是: 给你一些钱 m ,然后在这个国家买东西, 共有 n 件物品,每件物品有  价格 P    价值 V    还有一个很特别的属性 Q, Q 指 你如过想买这件物品 你的手中至少有这钱Q . 虽 ...

  3. HDU 3033 I love sneakers! 我爱运动鞋 (分组背包+01背包,变形)

    题意: 有n<=100双鞋子,分别属于一个牌子,共k<=10个牌子.现有m<=10000钱,问每个牌子至少挑1双,能获得的最大价值是多少? 思路: 分组背包的变形,变成了相反的,每组 ...

  4. [JSOI 2016] 最佳团体(树形背包+01分数规划)

    4753: [Jsoi2016]最佳团体 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 2003  Solved: 790[Submit][Statu ...

  5. HDU3466 背包DP

    Proud Merchants Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) ...

  6. 饭卡 (背包01 一维数组) http://acm.hdu.edu.cn/showproblem.php?pid=2546

    /* 从一组数据中选出n个数,使这n个数的和最接近一个值x, 背包问题, 从一系列菜中,从最贵的菜(MAX)之外中选出几个菜,使菜的总价格sum最接近money-5:money-sum-MAX; 钱数 ...

  7. HDU--杭电--4502--吉哥系列故事——临时工计划--背包--01背包

    吉哥系列故事——临时工计划 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) To ...

  8. HDU1864_最大报销额(背包/01背包)

    解题报告 pid=1864">题目传送门 #include <cstdio> #include <cstring> #include <iostream& ...

  9. 背包九讲 && 题目

    ★.背包求方案数的时候,多重背包是不行的,因为产生重复的背包会有多种情况. ★.背包记录路径的时候,其实是不行的,因为更新了12的最优解,如果它依赖于6这个背包,然后你后面改变了6这个背包,就GG 1 ...

随机推荐

  1. 理解C#事件

    前面文章中介绍了委托相关的概念,委托实例保存这一个或一组操作,程序中将在某个特定的时刻通过委托实例使用这些操作. 如果做过GUI程序开发,可能对上面的描述会比较熟悉.在GUI程序中,单击一个butto ...

  2. 【转】变量的声明和定义,从C到编译原理到C++,再到Java

    基础学了太久,时间一长有些东西就可能记得不太清楚,俗话说得好,"好记性不如烂笔头",所以把基础中的基础-变量的声明和定义,从C到编译原理到C++,再到Java用烂笔头记录下来 最早 ...

  3. WCF调用时提示错误 "已尝试创建到达不支持 .Net 框架的服务的通道。可能遇到 HTTP 终结点"

    一个以前运行的很正常的项目,某天突然无法连接WCF构建的后台.使用WCFTestClient连接到服务是正常的,但是调用服务中的方式时就报出了以下错误: 已尝试创建到达不支持 .Net 框架的服务的通 ...

  4. IntelliJ Idea13无法创建maven模板

    一.错误信息: -Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment v ...

  5. Tomcat_修改代码后tomcat是否需要重启

      在修改一个类时,如果没有修改到已经贮存于虚拟机的实例,在你重新编译后,发布至classes,都不需要重启. 怎样才叫已经贮存于虚拟机的实例呢: 1.成员变量 2.类名称 3.方法名 ………… 如果 ...

  6. 教你一步一步实现一个Promise

    Promise我想现在大家都非常熟悉了,主要作用就是解决异步回调问题,这里简单介绍下. Promise规范是CommonJS规范之一,而Promise规范又分了好多种,比如 Promises/A.Pr ...

  7. JS模式:又一个简单的工厂模式

    <!DOCTYPE html> <html> <head> <title></title> </head> <body&g ...

  8. hdu1561 树形dp + 背包

    #include<cstdio> #include<cstring> #include<iostream> #define INF 999999999 using ...

  9. hdu2072 字典树

    这题印象深刻,我刚接触acm时,以为这题是水题(因为是中文,又短),一直没做出.现再想想也是.可能也是我以前字符串掌握不好: 这题其实也可以用stl里的map写.这里我用字典树写的.其实这题算简单题了 ...

  10. Query对象与DOM对象之间的转换方法

    转自http://www.jquerycn.cn/a_4561 刚开始学习jQuery,可能一时会分不清楚哪些是jQuery对象,哪些是DOM对象.至于DOM对象不多解释,我们接触的太多了,下面重点介 ...