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
题目描述 一群小矮人掉进了一个很深的陷阱里,由于太矮爬不上来,于是他们决定搭一个人梯.即:一个小矮人站在另一小矮人的 肩膀上,知道最顶端的小矮人伸直胳膊可以碰到陷阱口.对于每一个小矮人,我们知道他从脚 ...
随机推荐
- POJ训练计划3422_Kaka's Matrix Travels(网络流/费用流)
解题报告 题目传送门 题意: 从n×n的矩阵的左上角走到右下角,每次仅仅能向右和向下走,走到一个格子上加上格子的数,能够走k次.问最大的和是多少. 思路: 建图:每一个格子掰成两个点,分别叫" ...
- 在eclipse中关联android源代码
1打包源代码成jar: 1 新建一个java项目 2 import 想打包的源代码文件 3 export 这个文件 : 选择java->jar file . 这里会让你选择输出路径 2 加 ...
- 51NOD 1686 第K大区间 二分
第k大区间 定义一个区间的值为其众数出现的次数.现给出n个数,求将所有区间的值排序后,第K大的值为多少. Input 第一行两个数n和k(1<=n<=100000,k<=n* ...
- MyEclipse2015安装SVN插件
一.下载SVN插件subclipse 下载地址:http://subclipse.tigris.org/servlets/ProjectDocumentList?folderID=2240 在打开的网 ...
- P1233 木棍加工
P1233 木棍加工 题目描述 一堆木头棍子共有n根,每根棍子的长度和宽度都是已知的.棍子可以被一台机器一个接一个地加工.机器处理一根棍子之前需要准备时间.准备时间是这样定义的: 第一根棍子的准备时间 ...
- 英语发音规则---C字母
英语发音规则---C字母 一.总结 一句话总结: 1.C发[k]音? cake [keɪk] n. 蛋糕 coat [kəʊt] n. 外套 music ['mjuːzɪk] n. 音乐,乐曲 pic ...
- c++面向对象程序设计 课后题 答案 谭浩强 第四章
c++面向对象程序设计课后题答案 谭浩强 第四章 1: #include <iostream> using namespace std; class Complex {public: Co ...
- PHPMailer使用说明
PHPMailer是一个用来发送电子邮件的函数包,远比PHP提供的mail()方便易用. 邮件格式说明 一封普通的电子邮件,通常是由发件人.收件人.抄送人.邮件标题.邮件内容.附件等内容构成.以下是一 ...
- Combox程序中自定义数据源
有combox控件,命名为cbxPutStatus,在程序中为其手工定义数据源,并绑定 private void POrderSplitFrm_Load(object sender, EventArg ...
- 服务端 | Nodejs 学习笔记(一)
Node.js 前言: 2009年面世 nodejs.org 官网 https://www.npmjs.com/ 模块社区 github.com 仓库 stackoverflow.com 问答社区 ...