PAT-Top1002. Business (35)
在一个项目的截止日期之前,如果工期有空闲则可能可以开展其他项目,提高效益。本题考查动态规划。数组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-Top1002. Business (35)的更多相关文章
- PAT顶级 1002. Business (35)
PAT顶级 1002. Business (35) As the manager of your company, you have to carefully consider, for each p ...
- PAT T1002 Business
背包问题,把任务按截止日期排序,再按背包问题处理~ #include<bits/stdc++.h> using namespace std; ; struct node { int c; ...
- R生存分析AFT
γ = 1/scale =1/0.902 α = exp(−(Intercept)γ)=exp(-(7.111)*γ) > library(survival) > myfit=survre ...
- PAT TOP 1005 Programming Pattern (35 分)哈希做法
1005 Programming Pattern (35 分) Programmers often have a preference among program constructs. For ex ...
- PAT (Top Level) Practise 1005 Programming Pattern (35)
后缀数组.排序之后得到height数组,然后从上到下将height>=len的都分为一组,然后找到第一组个数最多的输出即可. #pragma comment(linker, "/STA ...
- 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 ...
- PAT (Top Level)1002. Business DP/背包
As the manager of your company, you have to carefully consider, for each project, the time taken to ...
- 《转载》PAT 习题
博客出处:http://blog.csdn.net/zhoufenqin/article/details/50497791 题目出处:https://www.patest.cn/contests/pa ...
- PAT (Top Level) Practise 1008 Airline Routes(Tarjan模版题)
1008. Airline Routes (35) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue Given a ...
随机推荐
- 通过ModelForm实现主机添加和编辑
通过ModelForm实现主机添加和编辑 ModelForm这是一个神奇的组件,通过名字我们可以看出来,这个组件的功能就是把model和form组合起来:在使用Model和Form时,都需要对字段进行 ...
- asp.net core 缓存和Session
缓存 缓存在内存中 ASP.NET Core 使用 IMemoryCache内存中缓存是使用依赖关系注入从应用中引用的服务. 请在ConfigureServices中调用AddMemoryCache( ...
- 学习笔记: IO操作及序列化
/// <summary> /// 文件夹 文件管理 /// </summary> public class MyIO { /// <summary> ...
- JSP中out.print()、out.println()以及out.write()的区别
out是JSP九大内置对象之一,是JspWriter的一个对象,JspWriter继承了java.io.Writer类. out.print()和out.write() print()和println ...
- python全栈开发day86-CRM增删改查 分页
知识点梳理: 1.分页器保存搜索条件 2.ORM批量插入数据bulk_create 批量创建model实例,在用bulk_create 一次插入数据库 3.自定义不同表的不同字段ModelForm错误 ...
- JavaScript将数字转换为大写金额
用JavaScript将数字转换为大写金额,好了 0.0 To code! var digitUppercase = function(n) { var fraction = ['角', '分']; ...
- Oracle中start with...connect by子句的用法
http://www.blogjava.net/xzclog/archive/2010/03/05/314642.html
- 00-JAVA语法基础--动手动脑
1.运行EnumTest.java,并分析结果,得出结论. 其源代码以及运行结果截图如下: 枚举类型的常量以字符串的形式顺序储.源代码中s和t不是原始数据类型.getCLass():取得当前对象所属的 ...
- POJ 1330 Nearest Common Ancestors (模板题)【LCA】
<题目链接> 题目大意: 给出一棵树,问任意两个点的最近公共祖先的编号. 解题分析:LCA模板题,下面用的是树上倍增求解. #include <iostream> #inclu ...
- POJ 2299 Ultra-QuickSort (离散化)+【树状数组】
<题目链接> 题目大意: 给你一段序列,问你如果每次只交换该序列相邻的两个元素,最少需要交换多少步才能够使该序列变为升序排列. 解题分析: 不难发现,其实本题就是让我们求原始序列的逆序对, ...