HDU 3466 Proud Merchants (背包问题)
来源:互联网 发布:pplive网络电视官方 编辑:程序博客网 时间:2024/05/17 00:00
Proud Merchants
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 1899 Accepted Submission(s): 762
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?
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.
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 1010 15 105 10 53 105 10 53 5 62 7 3
Sample Output
511
题意:商品的价格是Pi, 你的钱要大于等于Qi才可以购买,购买商品所或得的价值Vi
背包问题:公式 dp[j]=dp[j]=Math.max(dp[j],dp[j-k1]+k2);
import java.io.*;import java.util.*;public class Main {int n,m,M=6000;int dp[]=new int[M];public static void main(String[] args) {new Main().work();}void work(){Scanner sc=new Scanner(new BufferedInputStream(System.in));while(sc.hasNext()){n=sc.nextInt();m=sc.nextInt();Node node[]=new Node[n];for(int i=0;i<n;i++){int a=sc.nextInt();int b=sc.nextInt();int c=sc.nextInt();node[i]=new Node(a,b,c);}Arrays.sort(node);//每件商品按 (this.qi-this.pi)>(o.qi-o.pi) 进行升序排序Arrays.fill(dp,0);for(int i=1;i<=n;i++){for(int j=m;j>=0;j--){if(j>=node[i-1].qi){int k1=node[i-1].pi;int k2=node[i-1].vi;dp[j]=Math.max(dp[j],dp[j-k1]+k2);}}}System.out.println(dp[m]);}}class Node implements Comparable<Node>{int pi;int qi;int vi;Node(int pi,int qi,int vi){this.pi=pi;this.qi=qi;this.vi=vi;}public int compareTo(Node o) {return (this.qi-this.pi)>(o.qi-o.pi)?1:-1;}}}
- HDU 3466 Proud Merchants (背包问题)
- hdu 3466 Proud Merchants(背包问题)
- HDU-3466-Proud Merchants(01背包问题)
- HDU 3466 Proud Merchants 01背包 单机调度问题
- hdu 3466Proud Merchants(01背包 单机调度问题)
- HDU 3466 Proud Merchants (01背包排序问题)
- HDU 3466 Proud Merchants 01背包
- hdu 3466 Proud Merchants(0/1背包)
- HDU 3466 Proud Merchants (背包)
- [01背包]HDU 3466 Proud Merchants
- HDU 3466 - Proud Merchants(01背包)
- HDU 3466 Proud Merchants(01背包)
- hdu 3466 Proud Merchants(01 背包)
- HDU--3466--Proud Merchants--01背包
- HDU 3466--Proud Merchants【01背包变形】
- hdu 3466 Proud Merchants(贪心+背包)
- hdu 3466(排序+背包)Proud Merchants
- HDU 3466(Proud Merchants)有条件01背包
- 第十五天(Using AJAX with Sencha Touch)
- 不懂带人,你就自己干到死
- Navicat备份转移数据库遇到 Column 'nature' has duplicated value '婆婆妈妈' in SET的处理办法
- libjvm.so:cannot restore segment prot after reloc:Permission denied
- android绘制过程
- HDU 3466 Proud Merchants (背包问题)
- DirectFB实例1--加载一幅图片
- 关于C,看过的一些书
- ArcGis for WPF 符号渲染
- Android有用代码片段(二)
- 《数据结构与程序设计---c++语言描述》第一章总结
- 《西游记》倒过来看
- Vim使用之配置文件
- oracle基本文件之控制文件