博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU3466背包01
阅读量:5089 次
发布时间:2019-06-13

本文共 1975 字,大约阅读时间需要 6 分钟。

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;
}

转载于:https://www.cnblogs.com/13224ACMer/p/4409493.html

你可能感兴趣的文章
js 过滤敏感词
查看>>
poj2752 Seek the Name, Seek the Fame
查看>>
软件开发和软件测试,我该如何选择?(蜗牛学院)
查看>>
基本封装方法
查看>>
bcb ole拖拽功能的实现
查看>>
生活大爆炸之何为光速
查看>>
bzoj 2456: mode【瞎搞】
查看>>
[Typescript] Specify Exact Values with TypeScript’s Literal Types
查看>>
[GraphQL] Reuse Query Fields with GraphQL Fragments
查看>>
Illustrated C#学习笔记(一)
查看>>
理解oracle中连接和会话
查看>>
两种最常用的Sticky footer布局方式
查看>>
Scrapy实战篇(三)之爬取豆瓣电影短评
查看>>
HDU 5510 Bazinga KMP
查看>>
[13年迁移]Firefox下margin-top问题
查看>>
Zookeeper常用命令 (转)
查看>>
Java程序IP v6与IP v4的设置
查看>>
RUP(Rational Unified Process),统一软件开发过程
查看>>
数据库链路创建方法
查看>>
Enterprise Library - Data Access Application Block 6.0.1304
查看>>