ZOJ3689 Digging(01背包)
#include <iostream>
#include <cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
int dp[][];
struct point{
int t,s;
}ps[];
bool cmp(point A, point B)
{
return A.t*B.s < B.t*A.s;//比较大小的时候千万不要 计算出数值进行比较
}
int main(){
int n,t;
int i,j;
while(cin>>n>>t){
for(i=;i<n;i++)
{
cin>>ps[i].t>>ps[i].s;
}
sort(ps,ps+n,cmp);
memset(dp,,sizeof(dp));
int ma=-;
for(i=;i<=n;i++){
for(j=ps[i-].t;j<=t;j++){
dp[i%][j]=max(dp[(i-)%][j],dp[(i-)%][j-ps[i-].t]+ps[i-].s*(t-(j-ps[i-].t)));
if(i==n) ma=max(ma,dp[i%][j]);
}
}
/* for(int i = 0; i < n; i++)
for(int j = t; j >= ps[i].t; j--){
int index=0;
dp[index][j] = max(dp[index][j], dp[index][j-ps[i].t]+(t-j+ps[i].t)*ps[i].s);
if(i==n-1) ma=max(ma,dp[index][j]);
}*/
cout<<ma<<endl;
}
return ;
}
ZOJ3689 Digging(01背包)的更多相关文章
- D - Digging(01背包,贪心)
D - Digging Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit St ...
- bnu 28890 &zoj 3689——Digging——————【要求物品次序的01背包】
Digging Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ID: 36 ...
- UVALive 4870 Roller Coaster --01背包
题意:过山车有n个区域,一个人有两个值F,D,在每个区域有两种选择: 1.睁眼: F += f[i], D += d[i] 2.闭眼: F = F , D -= K 问在D小于等于一定限度的时 ...
- POJ1112 Team Them Up![二分图染色 补图 01背包]
Team Them Up! Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7608 Accepted: 2041 S ...
- Codeforces 2016 ACM Amman Collegiate Programming Contest A. Coins(动态规划/01背包变形)
传送门 Description Hasan and Bahosain want to buy a new video game, they want to share the expenses. Ha ...
- 51nod1085(01背包)
题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1085 题意: 中文题诶~ 思路: 01背包模板题. 用dp[ ...
- *HDU3339 最短路+01背包
In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- codeforces 742D Arpa's weak amphitheater and Mehrdad's valuable Hoses ——(01背包变形)
题意:给你若干个集合,每个集合内的物品要么选任意一个,要么所有都选,求最后在背包能容纳的范围下最大的价值. 分析:对于每个并查集,从上到下滚动维护即可,其实就是一个01背包= =. 代码如下: #in ...
- POJ 3624 Charm Bracelet(01背包)
Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 34532 Accepted: 15301 ...
随机推荐
- tail -f
http://stackoverflow.com/questions/187587/looking-for-a-windows-equivalent-of-the-unix-tail-command ...
- [虚拟化/云] kvm的架构分析
预备知识 1. 客户机物理页框到宿主机虚拟地址转换 http://blog.csdn.net/zhuriyuxiao/article/details/8968781 http://www.tuicoo ...
- ldap理论属于概念缩略词
Standalone LDAP Daemon, slapd(standalone lightweight access protocol) ldap 389 default listener port ...
- c# 搭建服务端 常用的Helper(5)
常用的Helper 1.byteHelper :对象与byte[]之间的转换 2.ConvertJson:操作json对象 3.EncodingHelper:对象编码 4.ModelConvertHe ...
- hdu3280Equal Sum Partitions (区间DP)
Problem Description An equal sum partition of a sequence of numbers is a grouping of the numbers (in ...
- 2013年 ACM 有为杯 Problem I (DAG)
有为杯 Problem I DAG 有向无环图 A direct acylic graph(DAG),is a directed graph with no directed cycles . T ...
- 从零开始学习UNITY3D(GUI篇)
邻近年底,心也有些散乱,加上工作忙了一阵,在达内培训的课程也落下了不少.对unity3d的热度似乎也有点点下降.痛定思痛,又在淘宝上买了写蛮牛网的视频.总之不管是用任何手段都要逼着自己不要浪费了培训的 ...
- 微信小程序环境搭建
第一步 IDE下载 Win版链接: https://pan.baidu.com/s/1gfAy18n 第二步 破解 最新下载链接: https://pan.baidu.com/s/1gfAy18n ...
- 运行JBoss 5.1.0 GA时出现Error installing to Instantiated:name=AttachmentStore state=Described错误的解决办法
第一次开JBoss服务器:有些时候会遇到这种情况:把以下的文字替换即可 进到类似目录 server/default/conf/bootstrap,打开文件 profile.xml找到: Xml代码 & ...
- iOS手机号正则表达式并实现344格式 (正则的另一种实现方式)
[Demo下载地址]https://git.oschina.net/remainedmute/PhoneNumDemo.git 相关博客http://www.jianshu.com/p/00da4d8 ...