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
- 4
题解:先按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 ...
随机推荐
- HDU 4308 Saving Princess claire_(简单BFS)
求出不使用P点时起点到终点的最短距离,求出起点到所有P点的最短距离,求出终点到所有P点的最短距离. 答案=min( 不使用P点时起点到终点的最短距离, 起点到P的最短距离+终点到P的最短距离 ) #i ...
- Python中__name__属性的妙用
在Python中,每一个module文件都有一个built-in属性:__name__,这个__name__有如下特点: 1 如果这个module文件是被别的文件导入的,那么,该__name__属性的 ...
- Python中的global和nonlocal
在Python中,一个变量的scope范围从小到大分成4部分:Local Scope(也可以看成是当前函数形成的scope),Enclosing Scope(简单来说,就是外层函数形成的scope), ...
- 在线求助man page
一.举例——输入“man date” 图1 图2 图3 二.man之概述 用于:命令的使用说明 用法:man 命令 man page:执行“man 命令”后,出现的屏幕界面 补:man是manual( ...
- 基于NABCD评论“探路者”Alpha版作品
1.分析 N(Need):”为了重温贪吃蛇这一经典游戏,本组的选题定为贪吃蛇游戏,并在此基础上进行了新的创新,将普通的贪吃蛇游戏改为单词版贪吃蛇.市面上的英语单词背记软件对于那些缺少英语学习兴趣.毅力 ...
- Coursera-Note: Internet History, Technology and Secure (1st week to 9th week)
目录 Coursera-Note: Internet History, Technology and Secure 第一周 第二周 数据交换: Packet switching技术: 第三周 创造ht ...
- OSG学习:移动/缩放/旋转模型
移动和缩放以及旋转都是对矩阵进行操作,这些操作如果要叠加直接矩阵相乘就可以了. 下面的示例代码中,加入了四个bignathan,一个是默认加入在最中间,一个向上移2单位,一个是向下移2单位且缩放0.5 ...
- Python ZKPython 安装
1.由于python客户端依赖c的客户端所以要先安装c版本的客户端cd zookeeper-3.4.5/src/c./configuremake make install 2.下载python扩展包, ...
- SQL SERVER技术内幕之7 透视与逆透视
1.透视转换 透视数据(pivoting)是一种把数据从行的状态旋转为列的状态的处理,在这个过程中可能须要对值进行聚合. 每个透视转换将涉及三个逻辑处理阶段,每个阶段都有相关的元素:分组阶段处理相关的 ...
- sql sever 数据表
对视图进行操作,要在第三块区域进行添加记录操作,回车,然后会同步到所有相关数据表中. 记录不是列,而是行,不要混淆. 第二块区域是各个属性,就是说明: 第一块区域是要进行显示的字段,选中什么 显示什么 ...