Digging-贪心
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.

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 particularMaya 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 Tdays. 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 areT 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
Start the second task at the time 10
Start the first task at the time 9
Start the third task at the time 6
The answer is 10*2+9*4+6*1=62
#include"iostream"
#include"algorithm"
#include"cstring"
#include"queue"
#include"cmath"
#include"cstdio"
#include"cstdlib"
using namespace std;
#define sr(x) scanf("%d",&x)
#define sc(x) printf("%d",x)
#define hh printf("\n")
#define mod 1000000007
#define MAX(x,y) (x>y?x:y)
struct PP
{
int t,s;
};
int comp(PP x,PP y)
{
double l1,l2;
l1=(double)x.s*1.0/x.t;
l2=(double)y.s*1.0/y.t;
if(fabs(l1-l2)>0.00001)return l1>l2;
return x.t<y.t;
}
int main()
{
int n,tt,ss,ll[],i,j;
while(scanf("%d%d",&n,&tt)!=EOF)
{
ss=;
PP dd[];
for(i=;i<n;i++)
{
sr(dd[i].t);sr(dd[i].s);
}
memset(ll,,sizeof(ll));
sort(dd,dd+n,comp);
for(i=;i<n;i++)
{
for(j=tt;j>=dd[i].t;j--)
{
ll[j]=MAX(ll[j],ll[j-dd[i].t]+dd[i].s*(tt-j+dd[i].t));
ss=MAX(ss,ll[j]);
}
}
printf("%d\n",ss);
}
return ;
}
Digging-贪心的更多相关文章
- D - Digging(01背包,贪心)
D - Digging Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit St ...
- ZOJ 3689 Digging(贪心+dp)
Digging Time Limit: 2 Seconds Memory Limit: 65536 KB When it comes to the Maya Civilization, we ...
- 【贪心】【HDU3177】 搬家问题
</pre><pre name="code" class="cpp">#include <iostream> #includ ...
- BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]
1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1383 Solved: 582[Submit][St ...
- HDOJ 1051. Wooden Sticks 贪心 结构体排序
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]
1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 786 Solved: 391[Submit][S ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【BZOJ-4245】OR-XOR 按位贪心
4245: [ONTAK2015]OR-XOR Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 486 Solved: 266[Submit][Sta ...
- code vs 1098 均分纸牌(贪心)
1098 均分纸牌 2002年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 有 N 堆纸牌 ...
随机推荐
- vsftpd 自动安装脚本
#!/usr/bin/env python # -*- coding: utf-8 -*- __author__ = 'cpy' import os import re import sys impo ...
- mysql-mongdb-redis
千万级别:mysql 千万以及亿级别:mongdb
- Docker入门系列1:简介
可以实现快速部署. 比如一台 16 核 32G 内存的虚拟机上,需要跑 500+ 个用户的应用(每个应用的功能可以认为是一个网站 + 一系列的 RESTful API),有两个事情很重要: 资源隔离: ...
- 解决Oracle用户被锁定的方法
解决Oracle用户被锁定的方法 1,cmd控制台: 使用sqlplus 命令:sqlplus sys/密码@ip/orcl as sysdba; 2,先设置具体时间格式,以便查看具体时间 SQL&g ...
- python 基础 4.3 高阶函数下和匿名函数
一 .匿名函数 顾名思议就是没有名字的函数,那为什么要设立匿名函数,他有什么作用呢?lambda 函数就是一种快速定义单行的最小函数,可以用在任何需要函数的地方. 常规版: def fun(x,y ...
- EasyNVR RTSP转HLS(m3u8+ts)流媒体服务器前端构建之:bootstrap-datepicker日历插件的实时动态展现
EasyNVR中有对录像进行检索回放的功能,且先抛开录像的回放,为了更好的用户体验过.让用户方便快捷的找到对应通道对应日期的录像视频,是必须的功能. 基于上述的需求,为前端添加一个日历插件,在日历上展 ...
- jvm堆查看
jps查看jvm的进程号 jmap -histo:live [进程号] >log.txt dump jvm堆.
- JSP&Servlet(转)
第一篇:Web应用基础1.概念: 1.1应用程序分类 a.桌面应用程序:一般是指采用client/server即客户机/服务器结构的应用程序. b.web应用程序:一般是指采用Bro ...
- (转)js中__proto__和prototype的区别和关系
作者:doris链接:https://www.zhihu.com/question/34183746/answer/58155878来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请 ...
- (*)(转)要快速学习SSM框架,你需要一套学习曲线平滑的教程
作者:meepo链接:https://www.zhihu.com/question/57719761/answer/156952139来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载 ...