在一个项目的截止日期之前,如果工期有空闲则可能可以开展其他项目,提高效益。本题考查动态规划。数组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. Pymysql-总结

    背景:工作需要大量链接数据库进行一些操作查询,但是也会有出现异常情况 1.添加字段 1 ALTER TABLE app01_student ADD COLUMN Relation VARCHAR(25 ...

  2. 如何保证Redis的高并发

    单机的redis几乎不太可能说QPS超过10万+,一般在几万. 除非一些特殊情况,比如你的机器性能特别好,配置特别高,物理机,维护做的特别好,而且你的整体的操作不是太复杂. Redis通过主从架构,实 ...

  3. 一个良好划分Activity创建步骤的BaseActivity

    一个Activity的创建过程其实包含几个不同的步骤,基本上都是在onCreate函数中完成的,这些步骤主要有: 设置页面的布局文件 初始化页面包含的控件 设置页面控件的点击响应事件 处理页面的业务逻 ...

  4. 如何扩展Orchard

    翻译自: http://msdn.microsoft.com/en-us/magazine/hh708754.aspx     动态类型系统 Content item是Orchard中的原子, 比如b ...

  5. UOJ#275. 【清华集训2016】组合数问题 数位dp

    原文链接https://www.cnblogs.com/zhouzhendong/p/UOJ275.html 题解 用卢卡斯定理转化成一个 k 进制意义下的数位 dp 即可. 算答案的时候补集转化一下 ...

  6. AtCoder Grand Contest 002 (AGC002) F - Leftmost Ball 动态规划 排列组合

    原文链接https://www.cnblogs.com/zhouzhendong/p/AGC002F.html 题目传送门 - AGC002F 题意 给定 $n,k$ ,表示有 $n\times k$ ...

  7. maven聚合工程无法install

    对于maven聚合工程,有时候执行maven命令进行mvn clean install时会出一些莫名奇妙的错误: 一直报告找不到符号,仔细看了项目源代码也不知道是什么原因.首先确保项目所在路径为英文路 ...

  8. gdb调试若干问题

    1.若干命令速查 file <文件名>:加载被调试的可执行程序文件.因为一般都在被调试程序所在目录下执行GDB,因而文本名不需要带路径.示例:(gdb) file gdb-sample r ...

  9. 一、网络编程-UDP传输协议及socket套接字使用

    知识点基本介绍:1.网络通信协议一般就是UDP和TCP俩种传输协议,这一章先说UDP,UDP是一种比较简单的传输协议,如qq使用的就是UDP          2.ip:ip就是标记网络中中的一台电脑 ...

  10. Typescript 常见的几种函数重载方法详解与应用示例

    所谓的重载,其实就是使用相同的函数名,传入不同数量的参数或不同类型的参数,以此创建出多个方法或产生不同结果. 1. 最常见的,也就是根据定义傻瓜式地判断参数类型与数量 function showPer ...