在一个项目的截止日期之前,如果工期有空闲则可能可以开展其他项目,提高效益。本题考查动态规划。数组dp[i][t]表示在截止时间为t时,前i个项目工作安排能够产生的最大收益,而前i个项目的截止时间都不大于t。

 //#include "stdafx.h"
#include <iostream>
#include <algorithm>
#include <memory.h> using namespace std; struct node { // project struct
int p, l, d; // p is the profit, l is the lasting days of the project, d is the deadline
}pro[]; int cmp(node a, node b) { // sort rule
return a.d < b.d;
} int main() {
int n;
scanf("%d", &n); int i, maxd = ;
for (i = ; i <= n; i++) {
scanf("%d%d%d", &pro[i].p, &pro[i].l, &pro[i].d); if (pro[i].d > maxd) { // get the max deadline
maxd = pro[i].d;
}
} sort(pro + , pro + n + , cmp); int** dp = new int*[n + ];
for (i = ; i <= n; i++) {
dp[i] = new int[maxd + ];
memset(dp[i], , sizeof(dp[i])); // initialization : set value zero
} //printf("%d\n", dp[0][0]);
int j, t;
for (i = ; i <= n; i++) {
for (j = ; j <= maxd; j++) {
t = min(j, pro[i].d) - pro[i].l;
// get the max profit
if (t >= ) { // if can plus current project to compare the profit
dp[i][j] = max(pro[i].p + dp[i - ][t], dp[i - ][j]);
} else { // otherwise
dp[i][j] = dp[i - ][j];
}
}
} printf("%d\n", dp[n][maxd]); for (i = ; i <= n; i++) {
delete[] dp[i];
}
delete[] dp; system("pause");
return ;
}

参考资料

PAT. 1002. Business (35)

PAT-Top1002. Business (35)的更多相关文章

  1. PAT顶级 1002. Business (35)

    PAT顶级 1002. Business (35) As the manager of your company, you have to carefully consider, for each p ...

  2. PAT T1002 Business

    背包问题,把任务按截止日期排序,再按背包问题处理~ #include<bits/stdc++.h> using namespace std; ; struct node { int c; ...

  3. R生存分析AFT

    γ = 1/scale =1/0.902 α = exp(−(Intercept)γ)=exp(-(7.111)*γ) > library(survival) > myfit=survre ...

  4. PAT TOP 1005 Programming Pattern (35 分)哈希做法

    1005 Programming Pattern (35 分) Programmers often have a preference among program constructs. For ex ...

  5. PAT (Top Level) Practise 1005 Programming Pattern (35)

    后缀数组.排序之后得到height数组,然后从上到下将height>=len的都分为一组,然后找到第一组个数最多的输出即可. #pragma comment(linker, "/STA ...

  6. PAT 1009. Triple Inversions (35) 数状数组

    Given a list of N integers A1, A2, A3,...AN, there's a famous problem to count the number of inversi ...

  7. PAT (Top Level)1002. Business DP/背包

    As the manager of your company, you have to carefully consider, for each project, the time taken to ...

  8. 《转载》PAT 习题

    博客出处:http://blog.csdn.net/zhoufenqin/article/details/50497791 题目出处:https://www.patest.cn/contests/pa ...

  9. PAT (Top Level) Practise 1008 Airline Routes(Tarjan模版题)

    1008. Airline Routes (35) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue Given a ...

随机推荐

  1. SQL Server索引维护

    索引维护的两个重要方面是索引碎片和统计信息. 一:索引碎片 降低碎片的产生,当索引上的页不在具有物理连续性时,就会产生碎片,下面的情景会产生碎片: INSERT操作.UPDATE操作.DBCC SHR ...

  2. SQLServer 常见高CPU利用率原因

    1.缺失索引: USE AdventureWorks2014 SET STATISTICS TIME ON; SET STATISTICS IO ON ; SELECT per.FirstName,p ...

  3. linux系统(CentOS7)虚拟机上安装oracle 11g,解决oracle图形界面卡住无法点击next问题

    https://www.cnblogs.com/nichoc/p/6416475.html

  4. IPMI无法执行命令

    IPMI无法执行命令 https://www.cnblogs.com/EricDing/p/8995263.html http://www.cnblogs.com/heidsoft/p/4014301 ...

  5. 深入了解Cookie

    1.Cookie是什么 1.由于http是无状态的协议,一旦客户端和服务器的数据交换完毕,就会断开连接,再次请求,会重新连接,无法存储数据.2.Cookie的出现是为了下次链接时,你之前存储了哪些数据 ...

  6. 考虑实现一个不抛异常的swap

    Effective C++:参考自harttle land 类的swap实现与STL容器是一致的:提供swap成员函数, 并特化std::swap来调用那个成员函数. class Widget { p ...

  7. [SDOI2018]原题识别

    题解: ..感觉挺烦得 而且我都没有注意到树随机这件事情.. 就写个30分的莫队.. #include <bits/stdc++.h> using namespace std; #defi ...

  8. spring security实现动态配置url权限的两种方法

    缘起 标准的RABC, 权限需要支持动态配置,spring security默认是在代码里约定好权限,真实的业务场景通常需要可以支持动态配置角色访问权限,即在运行时去配置url对应的访问角色. 基于s ...

  9. js将时间戳转为时间格式

    时间戳转时间格式 //分钟 let timeM= parseInt(msg/1000/60%60); if(timeM<10){ timeM="0"+timeM; } //秒 ...

  10. BeanFactory和FactoryBean的区别

    转自:http://blog.csdn.net/wangbiao007/article/details/53183764 1.BeanFactory BeanFactory是IOC最基本的容器,负责生 ...