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

    <div class="btn-group" data-toggle="buttons" id="radio"> <lab ...

  2. SQL Server中Text和varchar(max) 区别

    SQL Server 2005之后版本:请使用 varchar(max).nvarchar(max) 和 varbinary(max) 数据类型,而不要使用 text.ntext 和 image 数据 ...

  3. org.apache.thrift.transport.TTransportException: Could not create ServerSocket on address 0.0.0.0/0.0.0.0:9083.

    1.启动hive的过程中,[hadoop@slaver1 soft]$ hive --service metastore &错误如下所示: 原因:之前启动hive失败了,但是进程以及启动起来, ...

  4. webpack学习笔记--其它配置项

     其它配置项 除了前面介绍到的配置项外,Webpack 还提供了一些零散的配置项.下面来介绍它们中常用的部分. Target JavaScript 的应用场景越来越多,从浏览器到 Node.js,这些 ...

  5. Vs2017获取Git空仓库后创建解决方案及项目无法推送,推送失败的问题.

      与Git无关,因为远程是空文件夹,导致没有远程版本做对应提示更改或怎样,必须在创建人创建仓库的时候上传文件代码. https://developercommunity.visualstudio.c ...

  6. 彻底明确怎样设置minSdkVersion和targetSdkVersion

    minSdkVersion和targetSdkVersion相信非常多人都不太理解.我在网上也看了很多关于这两者差别的文章,感觉说的都非常模糊.直到我在stackOverFlow看到Android M ...

  7. Asp.Net Mvc 返回类型总结

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  8. vue中的provide/inject的学习使用

    irst:定义一个parent component ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 <template>  <div> ...

  9. JavaMelody 项目性能监控和调优工具

    转自 JavaMelody 可以实现对内存.CPU.线程.JDBC 连接数.HTTP 请求执行时间.SQL 执行时间(分析 Top SQL).方法执行时间(分析系统方法性能瓶颈)等等的监控. 配置方式 ...

  10. java分页实现

    虽然现在有很多好用的框架,对分页进行支持,很简单的就把分页的效果做出来,但是如果自己手写是一个怎样的流程的?今天就来说说它,手动实现分页效果. 一.分页的思路 首先我们得知道写分页代码时的思路,保持思 ...