PAT (Top Level)1002. Business DP/背包
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
题解:先按deadline排序,把时间作为背包就行了。
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std; struct sion
{
int v, c, d;
}a[]; int cmp(sion a, sion b)
{
if(a.d!= b.d)
return a.d < b.d;
else
return a.c < b.c;
} int dp[][];
int main()
{
int n;
int sum ,ma ;
while(cin >> n)
{
sum = ;
for(int i = ; i <= n; i++)
{
cin >> a[i].v >> a[i].c>> a[i].d;
sum += a[i].c;
dp[i][] = ;
}
sort(a + , a + n + , cmp);
ma = ;
dp[][] = ;
for(int i = ; i <= n; i++ )
{
for(int j = ; j <= sum; j++)
{
if(j <= a[i].d)
{
dp[i][j] = max(dp[i-][j-a[i].c]+a[i].v, dp[i-][j]);
}
else
{
dp[i][j] = a[i].v;
}
ma = max(ma, dp[i][j]);
}
} printf("%d\n", ma); }
}
PAT (Top Level)1002. Business DP/背包的更多相关文章
- PAT (Top Level) Practise 1008 Airline Routes(Tarjan模版题)
1008. Airline Routes (35) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue Given a ...
- PAT (Basic Level) 1002. 写出这个数 (20)
读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式:每个测试输入包含1个测试用例,即给出自然数n的值.这里保证n小于10100. 输出格式:在一行内输出n的各位数字之和的每 ...
- PAT (Top Level) Practise 1005 Programming Pattern (35)
后缀数组.排序之后得到height数组,然后从上到下将height>=len的都分为一组,然后找到第一组个数最多的输出即可. #pragma comment(linker, "/STA ...
- PAT (Advanced Level) 1002. A+B for Polynomials (25)
为0的不要输出. #include<iostream> #include<cstring> #include<cmath> #include<algorith ...
- PAT顶级 1002. Business (35)
PAT顶级 1002. Business (35) As the manager of your company, you have to carefully consider, for each p ...
- PAT (Advanced Level) Practice 1002 A+B for Polynomials (25 分) 凌宸1642
PAT (Advanced Level) Practice 1002 A+B for Polynomials (25 分) 凌宸1642 题目描述: This time, you are suppos ...
- PAT (Advanced Level) Practice 1001-1005
PAT (Advanced Level) Practice 1001-1005 PAT 计算机程序设计能力考试 甲级 练习题 题库:PTA拼题A官网 背景 这是浙大背景的一个计算机考试 刷刷题练练手 ...
- invalid nib registered for identifier (重用符) - nib must contain exactly one top level object which must be a UITableViewCell instance'
通过xib创建cell的时候 一定要注意!!! 这个错误是在这个xib中在View同一层级出现了其他的控件,检查一下xib中左边的层级关系,让cell的view是唯一的控件就可以了,否则一执行 就会提 ...
- 什么时候需要交换Top Level ?
什么时候需要交换Top Level ? 上一篇中提到,如果采用仿真的时候,运用门级仿真就需要进行顶层交换,RTL仿真不需要,那么什么时候需要呢? QuartusII 向下包含,在Project Nav ...
随机推荐
- 什么是Frozen Binary
对于Python来说,你可以将Python的字节码,PVM(也就是解析器),以及需要的相关类库,打包成一个package,这个package实际上是一个二进制可执行文件,这样,用户获取到这个packa ...
- SFTP服务器之创建普通用户
这篇博客主要写以下几点: 1.介绍SFTP服务器 2.用SFTP服务器的root用户a创建普通用户 3.修改普通用户名称以及默认登入时的目录名称 4.创建普通用户踩过的坑以及收获 一.介绍SFTP服务 ...
- 第十七次ScrumMeeting会议
第十七次Scrum Meeting 时间:2017/12/7 地点:线上+主235 人员:蔡帜 王子铭 游心 解小锐 王辰昱 李金奇 杨森 陈鑫 赵晓宇 照片: 目前工作进展 名字 今日 明天的工作 ...
- [solution]xdebug正确配置,但不显示错误信息
一开始以为是配置问题,其实不是,折腾了好久,貌似中文网页很少有人提到这事,更别提解决之道! 最好还是用英文关键词google之:得如下网页 https://bugs.launchpad.net/ubu ...
- Python 零碎信息-基础 01
1. """ 可以插入多行文字. print """ abC 123' 456''" #单引号, 双引号, 也没有关系 " ...
- YaoLingJump开发者日志(一)
写完PokeCats之后意犹未尽,还想做一个更加有趣的游戏,比如说像超级玛丽那样. 游戏的主角就选"瑶玲"了,这是我小时候最喜欢的动画片<瑶玲啊瑶玲>的女主角. ...
- 修改IntelliJ IDEA代码头注释
- mysql指定编码格式创建数据库
CREATE DATABASE `dev` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
- Kafka性能之道
Kafka高性能之道 高效使用磁盘 零拷贝 批处理和压缩 Partition ISR 高效使用磁盘 >顺序写cipan >Append Only(数据不更新,无记录级的数据删除,只会整个s ...
- wpf 验证方法
效果图,当放鼠标到文本框上会显示出错的提示.