HDU3466背包01
2015-04-09 13:57
218 查看
Proud Merchants
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 3126 Accepted Submission(s): 1288
[align=left]Problem Description[/align]
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?
[align=left]Input[/align]
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.
[align=left]Output[/align]
For each test case, output one integer, indicating maximum value iSea could get.
[align=left]Sample Input[/align]
2 10 10 15 10 5 10 5 3 10 5 10 5 3 5 6 2 7 3
[align=left]Sample Output[/align]
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背包排序)
- HDU3466-Proud Merchants(01背包变形)
- hdu3466_01背包变形 理解无后效性
- HDU3466 Proud Merchants (01背包变形)
- Proud Merchants(01背包变形)hdu3466
- hdu3466 Proud Merchants 变形01背包
- 01背包问题和完全背包问题 (转载)
- 01背包的c语言实现
- nyoj 860 (01背包 变形)
- 【01背包求第K优解】HDU 2639 Bone Collector II
- 01背包问题
- hdu1203(01背包微变形)
- hihocoder —— #1038 : 01背包
- 背包问题(01背包,完全背包,多重背包)
- 01背包问题
- 关于背包九讲01背包中的常数优化
- HDU 3466 01背包变形
- 动态规划01背包问题
- 【hihocoder】#1038 : 01背包
- 百练 4102 宠物小精灵之收服 【二维费用01背包】