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. Scala 中的函数式编程基础(一)

    主要来自 Scala 语言发明人 Martin Odersky 教授的 Coursera 课程 <Functional Programming Principles in Scala>. ...

  2. 安装及破解IntelliJ IDEA15

    1. 下载安装包 进入 JetBrains 官网,http://www.jetbrains.com/idea/download/#tabs_1=windows, 从Ultimate下载企业版 Inte ...

  3. java核心数据结构总结

    JDK提供了一组主要的数据结构的实现,如List.Set.Map等常用结构,这些结构都继承自java.util.collection接口. List接口 List有三种不同的实现,ArrayList和 ...

  4. final和static

    /*    final修饰符  1. final修饰的类不能被继承,没有子类  2. final修饰的方法不能被子类覆盖  3. final修饰的变量表示常量,只能被赋值一次  4. final 修饰 ...

  5. simple-LDAP-auth / ldap_auth.php

    <?php /** * simple class for LDAP authentification * Copyright (C) 2013 Petr Palas This program i ...

  6. 通过smtp协议简单实现邮件发送

    使用到的类: ①SmtpClient--发送邮件的类(using System.Net.Mail;) ②MailMessage--初始化邮件的类 ③ NetworkCredential--身份验证的类 ...

  7. iOS开发获取本机手机号码

    最近有个奇葩需求,用户登录返回手机号匹配本机号码相同才可以登录,吓得我虎躯一震,经了解,iOS7后不越狱实现不了 "For security reasons, iPhone OS restr ...

  8. MongoDB的安装及配置

    MongoDB 是目前在IT行业非常流行的一种非关系型数据库(NoSql),其灵活的数据存储方式备受当前IT从业人员的青睐. Windows (1). 登录Mongodb官网点击下载 (2). 将zi ...

  9. ios学习笔记

    1.对于autorelease的理解 Each thread in a Cocoa application maintains its own stack of autorelease pool bl ...

  10. c++实现gray code(格雷码)

    今天别人问的一道题,强调用分治法实现 =.= 百度了一下格雷码,然后写了一下. 关于格雷码大家看百度的吧,特别详细,贴个图: 代码如下(header_file.h是我自己写的一个头文件,包括常见的ve ...