博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PAT顶级 1002. Business (35)
阅读量:6909 次
发布时间:2019-06-27

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

PAT顶级 1002. Business (35)


As the manager of your company, you have to carefully consider, for each project, the time taken to finish it, the deadline, and the profit you can gain, in order to decide if your group should take this project. For example, given 3 projects as the following:

Project[1] takes 3 days, it must be finished in 3 days in order to gain 6 units of profit.
Project[2] takes 2 days, it must be finished in 2 days in order to gain 3 units of profit.
Project[3] takes 1 day only, it must be finished in 3 days in order to gain 4 units of profit.
You may take Project[1] to gain 6 units of profit. But if you take Project[2] first, then you will have 1 day left to complete Project[3] just in time, and hence gain 7 units of profit in total. Notice that once you decide to work on a project, you have to do it from beginning to the end without any interruption.

Input Specification


Each input file contains one test case. For each case, the first line gives a positive integer N(<=50), and then followed by N lines of projects, each contains three numbers P, L, and D where P is the profit, L the lasting days of the project, and D the deadline. It is guaranteed that L is never more than D, and all the numbers are non-negative integers.

Output Specification


For each test case, output in a line the maximum profit you can gain.

Sample Input


4

7 1 3
10 2 3
6 1 2
5 1 1

Sample Output


18

设dp[i][j]表示考虑到第i个项目,前一个项目结束时间为j的最大收益,那么可得DP方程为:

dp[i][j+a[i].l]=max(dp[i][j+a[i].l],dp[k][j]) if(j+a[i].l<=a[i].d)
由于没有说明数据范围,只能使用map表示二维dp数组了

#include #include 
#include
using namespace std;struct node{ int p,l,d; node() {} node(int tp,int tl,int td) { p=tp; l=tl; d=td; } bool operator < (const node &an) const { return d
>dp;int main(){ int n,p,l,d; while(cin>>n) { for(int i=1; i<=n; i++) { cin>>p>>l>>d; a[i]=node(p,l,d); } a[0]=node(0,0,0); sort(a+1,a+1+n); dp.clear(); ll ans=0; for(int i=1; i<=n; i++) { for(int j=0; j<=a[i-1].d; j++) { if(j+a[i].l<=a[i].d) { for(int k=0;k

转载于:https://www.cnblogs.com/zsyacm666666/p/6936625.html

你可能感兴趣的文章
中国象棋程序的设计与实现(七)--心得体会和开发日志
查看>>
浅显理解 Python 闭包
查看>>
学习Oracle分析函数(Analytic Functions)
查看>>
openstack学习笔记二 网络设置基础
查看>>
RabbitMQ基础
查看>>
有了安全边界,人工智能才能有序发展
查看>>
Qt在mainwindow下代码添加控件不能显示的问题
查看>>
【cocos2dx】使用VS插件在VS2012/2013上编辑和调试Quick-Cocos2d-x的Lua代码
查看>>
Centos6.0之pptpd+mysql+freeradius实现***帐号统一认证管理
查看>>
Excel导出数据
查看>>
解释Windows7“上帝模式”的原理
查看>>
httpClient4.* 使用教程
查看>>
相对和绝对路径、cd命令、创建和删除目录mkdir/rmdir 、rm命令
查看>>
yum安装配置nagios
查看>>
linux下Bash局部变量及信号捕捉等概念解释
查看>>
HTML5 input placeholder 颜色修改示例css
查看>>
cacti-0.8.8c 下安装realtime插件
查看>>
我的友情链接
查看>>
从0开始学大数据-Java基础开篇(1)
查看>>
github常用命令总结(一)
查看>>