ZOJ 3689 Digging(贪心+dp)
Digging
Time Limit: 2 Seconds Memory Limit: 65536 KB
When it comes to the Maya Civilization, we can quickly remind of a term called the end of the world. It's not difficult to understand why we choose to believe the prophecy
(or we just assume it is true to entertain ourselves) if you know the other prophecies appeared in the Maya Calendar. For instance, it has accurately predicted a solar eclipse on July 22, 2009.
name=digging-pyramid1.jpg" alt="">
The ancient civilization, such as Old Babylonianhas, Ancient Egypt and etc, some features in common. One of them is the tomb because of the influence of the religion.
At that time, the symbol of the tomb is the pyramid. Many of these structures featured a top platform upon which a smaller dedicatory building was constructed, associated with a particular Maya deity. Maya pyramid-like structures were also erected
to serve as a place of interment for powerful rulers.
Now there are N coffin chambers in the pyramid waiting for building and the ruler has recruited some workers to work for T days. It takes ti days to complete
the ith coffin chamber. The size of the ith coffin chamber is si. They use a very special method to calculate the reward for workers. If starting to build the ith coffin chamber when there are t days left,
they can get t*si units of gold. If they have finished a coffin chamber, then they can choose another coffin chamber to build (if they decide to build the ith coffin chamber at the time t, then they can decide next coffin chamber
at the time t-ti).
At the beginning, there are T days left. If they start the last work at the time t and the finishing time t-ti < 0, they will not get the last
pay.
Input
There are few test cases.
The first line contains N, T (1 ≤ N ≤ 3000,1 ≤ T ≤ 10000), indicating there are N coffin chambers to be built, and there are T days
for workers working. Next N lines contains ti, si (1 ≤ti, si ≤ 500).
All numbers are integers and the answer will not exceed 2^31-1.
Output
For each test case, output an integer in a single line indicating the maxminal units of gold the workers will get.
Sample Input
3 10
3 4
1 2
2 1
Sample Output
62
Hint
至于为什么。我也不知道,(看来还是没參透dp的精髓。
。),想来大概是背包得先背性价比高的来保证贪心的思想吧。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std; const int M=10010;
const int N=3030; int n,T;
ll dp[M];
struct node {
int t,v;
} a[N]; bool cmp(node a,node b) {
return a.v*b.t<a.t*b.v;
} int main() {
// freopen("test.in","r",stdin);
while(~scanf("%d%d",&n,&T)) {
for(int i=0; i<n; i++)
scanf("%d%d",&a[i].t,&a[i].v);
sort(a,a+n,cmp);
memset(dp,0,sizeof dp);
for(int i=0; i<n; i++) {
for(int j=T; j>=a[i].t; j--) {
dp[j]=max(dp[j],dp[j-a[i].t]+a[i].v*j);
}
}
printf("%lld\n",dp[T]);
}
return 0;
}
ZOJ 3689 Digging(贪心+dp)的更多相关文章
- ZOJ 3689 Digging(DP)
Description When it comes to the Maya Civilization, we can quickly remind of a term called the end o ...
- bnu 28890 &zoj 3689——Digging——————【要求物品次序的01背包】
Digging Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ID: 36 ...
- ZOJ 3905 Cake(贪心+dp)
动态规划题:dp[i][j]表示有i个Cake,给了Alice j个,先按照b排序,这样的话,能保证每次都能成功给Alice Cake,因为b从大到小排序,所以Alice选了j个之后,Bob最少选了j ...
- Digging(DP)
ZOJ Problem Set - 3689 Digging Time Limit: 2 Seconds Memory Limit: 65536 KB When it comes to th ...
- 【BZOJ-3174】拯救小矮人 贪心 + DP
3174: [Tjoi2013]拯救小矮人 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 686 Solved: 357[Submit][Status ...
- BZOJ_3174_[Tjoi2013]拯救小矮人_贪心+DP
BZOJ_3174_[Tjoi2013]拯救小矮人_贪心+DP Description 一群小矮人掉进了一个很深的陷阱里,由于太矮爬不上来,于是他们决定搭一个人梯.即:一个小矮人站在另一小矮人的 肩膀 ...
- 洛谷P4823 拯救小矮人 [TJOI2013] 贪心+dp
正解:贪心+dp 解题报告: 传送门! 我以前好像碰到过这题的说,,,有可能是做过类似的题qwq? 首先考虑这种显然是dp?就f[i][j]:决策到了地i个人,跑了j个的最大高度,不断更新j的上限就得 ...
- 【bzoj5073】[Lydsy1710月赛]小A的咒语 后缀数组+倍增RMQ+贪心+dp
题目描述 给出 $A$ 串和 $B$ 串,从 $A$ 串中选出至多 $x$ 个互不重合的段,使得它们按照原顺序拼接后能够得到 $B$ 串.求是否可行.多组数据. $T\le 10$ ,$|A|,|B| ...
- 【bzoj3174】[Tjoi2013]拯救小矮人 贪心+dp
题目描述 一群小矮人掉进了一个很深的陷阱里,由于太矮爬不上来,于是他们决定搭一个人梯.即:一个小矮人站在另一小矮人的 肩膀上,知道最顶端的小矮人伸直胳膊可以碰到陷阱口.对于每一个小矮人,我们知道他从脚 ...
随机推荐
- Linux 网卡驱动学习(六)(应用层、tcp 层、ip 层、设备层和驱动层作用解析)
本文将介绍网络连接建立的过程.收发包流程,以及当中应用层.tcp层.ip层.设备层和驱动层各层发挥的作用. 1.应用层 对于使用socket进行网络连接的server端程序.我们会先调用socket函 ...
- iOS开发中权限再度梳理
前言 上篇文章iOS开发中的这些权限,你搞懂了吗?介绍了一些常用权限的获取和请求方法,知道这些方法的使用基本上可以搞定大部分应用的权限访问的需求.但是,这些方法并不全面,不能涵盖住所有权限访问的方法. ...
- python之路——装饰器函数
阅读目录 楔子 装饰器的形成过程 开放封闭原则 谈装饰器主要功能和装饰器固定结构 带参数的装饰器 多个装饰器装饰一个函数 返回顶部 楔子 作为一个会写函数的python开发,我们从今天开始要去公司上班 ...
- javascript动画函数封装(升级版)
//把 任意对象 的 任意数值属性 改变为 任意的目标值 function animate(obj, json, fn) { clearInterval(obj.timer); obj.timer = ...
- MySQL高级查询和编程基础
第一章 数据库设计 一.数据需求分析: 数据需求分析是为后续概念设计和逻辑结构设计做准备. 结构:(1)对现实世界要处理的对象进行详细的调查. (2)收集基础数.据. (3)对所收集的数据进行处理. ...
- DevExpress Report 打印提示one or more margins are set outside the printable area of the page 问题解决
DevExpress Report Print的时候,出现这样的问题:one or more margins are set outside the printable area of the pa ...
- Eclipse键盘输出文字,显示到屏幕上方法
方法1 /*标准的思路: * 分析: * 1.来源 * 键盘:System.in * 2.目的地 * 屏幕:System.out * 文件:FIle * 3.分别分析:源,目的地流的类型(字符,字节) ...
- C语言宏定义#define用法
#define是C语言中提供的宏定义命令,其主要目的是为程序员在编程时提供一定的方便,并能在一定程度上提高程序的运行效率,但学生在学习时往往不能 理解该命令的本质,总是在此处产生一些困惑,在编程时误用 ...
- SecurityManager USE
import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io. ...
- Cacti部署之配置防火墙
因为SNMP协议通信会使用udp 的161端口和tcp的199端口,因此需要在防火墙上将其开启 开启入站端口 保存数据或者重启服务 测试SNMP工具连接是否可获取信息 注意:要能使用s ...