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 BabylonianhasAncient 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 NT (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 tisi (1 ≤tisi ≤ 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

题意:n个任务,剩余t的时间,完毕每一个任务会消耗时间ti,同一时候也会得到t*si的价值,求怎么安排任务得到的价值最大
题解:一開始仅仅想用背包,出不来例子。排个序后就能够了。

至于为什么。我也不知道,(看来还是没參透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)的更多相关文章

  1. ZOJ 3689 Digging(DP)

    Description When it comes to the Maya Civilization, we can quickly remind of a term called the end o ...

  2. bnu 28890 &zoj 3689——Digging——————【要求物品次序的01背包】

    Digging Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ID: 36 ...

  3. ZOJ 3905 Cake(贪心+dp)

    动态规划题:dp[i][j]表示有i个Cake,给了Alice j个,先按照b排序,这样的话,能保证每次都能成功给Alice Cake,因为b从大到小排序,所以Alice选了j个之后,Bob最少选了j ...

  4. Digging(DP)

    ZOJ Problem Set - 3689 Digging Time Limit: 2 Seconds      Memory Limit: 65536 KB When it comes to th ...

  5. 【BZOJ-3174】拯救小矮人 贪心 + DP

    3174: [Tjoi2013]拯救小矮人 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 686  Solved: 357[Submit][Status ...

  6. BZOJ_3174_[Tjoi2013]拯救小矮人_贪心+DP

    BZOJ_3174_[Tjoi2013]拯救小矮人_贪心+DP Description 一群小矮人掉进了一个很深的陷阱里,由于太矮爬不上来,于是他们决定搭一个人梯.即:一个小矮人站在另一小矮人的 肩膀 ...

  7. 洛谷P4823 拯救小矮人 [TJOI2013] 贪心+dp

    正解:贪心+dp 解题报告: 传送门! 我以前好像碰到过这题的说,,,有可能是做过类似的题qwq? 首先考虑这种显然是dp?就f[i][j]:决策到了地i个人,跑了j个的最大高度,不断更新j的上限就得 ...

  8. 【bzoj5073】[Lydsy1710月赛]小A的咒语 后缀数组+倍增RMQ+贪心+dp

    题目描述 给出 $A$ 串和 $B$ 串,从 $A$ 串中选出至多 $x$ 个互不重合的段,使得它们按照原顺序拼接后能够得到 $B$ 串.求是否可行.多组数据. $T\le 10$ ,$|A|,|B| ...

  9. 【bzoj3174】[Tjoi2013]拯救小矮人 贪心+dp

    题目描述 一群小矮人掉进了一个很深的陷阱里,由于太矮爬不上来,于是他们决定搭一个人梯.即:一个小矮人站在另一小矮人的 肩膀上,知道最顶端的小矮人伸直胳膊可以碰到陷阱口.对于每一个小矮人,我们知道他从脚 ...

随机推荐

  1. 使用Swift和SpriteKit写一个忍者游戏

    这篇文章的游戏使用SpriteKit和Swift语言来完毕. SpriteKit是苹果自己的游戏引擎,更能贴合iOS系统底层的API,只是架构和实现上都是模仿了Cocos2D.所以使用上事实上区别不大 ...

  2. Llama-impala on yarn的中间协调服务

    本文基于CDH发行版下的Hadoop Yarn和Impala 早期的Impala版本号中.为了使用Impala.我们一般会在以Client/Server的结构在各个集群节点启动impala-serve ...

  3. UVA 11825 Hackers’ Crackdown 状压DP枚举子集势

    Hackers’ Crackdown Miracle Corporations has a number of system services running in a distributed com ...

  4. Rsync 服务器搭建

    Rsync简介 rsync 是一个 Unix 系统下的文件同步和传输工具. 它具备以下特性: 1. 能更新整个目录和树和文件系统 2. 有选择性的保持符号链链.硬链接.文件属于.权限.设备以及时间 等 ...

  5. sql server 授权相关命令

    原文:https://blog.csdn.net/hfdgjhv/article/details/83834076 https://www.cnblogs.com/shi-yongcui/p/7755 ...

  6. HTTP_PROXY

    Linux, macOS, or Unix: $ export HTTP_PROXY=http://a.b.c.d:n $ export HTTPS_PROXY=http://w.x.y.z:m 设置 ...

  7. 洛谷P3358 最长k可重区间集问题(费用流)

    题目描述 对于给定的开区间集合 I 和正整数 k,计算开区间集合 I 的最长 k可重区间集的长度. 输入输出格式 输入格式: 的第 1 行有 2 个正整数 n和 k,分别表示开区间的个数和开区间的可重 ...

  8. 搭建svn服务器(ubuntu)

    ubuntu搭建svn服务器 环境:ubuntu 12.04.5 apt-get install subversion 找个目录作为svn的仓库 mkdir svn svnadmin create s ...

  9. 第一次接触Arduino

    1.百度百科: Arduino包含两个主要的部分:硬件部分是可以用来做电路连接的Arduino电路板:另外一个则是 Arduino IDE,你的计算机中的程序开发环境.你只要在IDE中编写程序代码,将 ...

  10. Xcode7 下导入第三方库 图文介绍

    网上没有很好的图文介绍,干脆我自己写一个好了,方便新手入门. 这里以导入著名的第三方网络库AFNetWorking v3.0.4和数据库FMDB v2.6.2为例进行说明. 好,下面开始. 下载源文件 ...