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 ...
随机推荐
- Perfmon 介绍
1.UI 1.笔图标,可以把视图里的细线加粗. 2.加号图标.可以为视图添加新的记数器. 3.操作-->属性.可以用于设置默认的采样时间. 2.增加计数据器页面 1.一个计数据器会包涵多个对象. ...
- Matlab 之meshgrid, interp, griddata 用法和实例
http://blog.sina.com.cn/s/blog_67f37e760101bu4e.html 实例结果http://wenku.baidu.com/link?url=SiGsFZIxuS1 ...
- C语言-字符编码转换:UTF与GB2312
依赖库libiconv,libiconv库的交叉编译不做描述,网上很多 #include <stdio.h> #include <stdlib.h> #include < ...
- 项目关联不上开源项目(library)
首先是add library的时候重新打开始始终显示关联错误,在reference中出现一个红叉,无论如何都解决不了,remove后重新添加也会有这个问题,Eclipse也没有任何出错提示. 最后在h ...
- chromedriver bug
https://github.com/FuckTheWorld/chromedriver/issues/1145 https://bugs.chromium.org/p/chromedriver/is ...
- Codeforces 263E
Codeforces 263E 原题 题目描述:一个\(n \times m\)的矩阵,每格有一个数,给出一个整数\(k\),定义函数\(f(x, y)\): \[f(x, y)=\sum_{i=1} ...
- jQuery Pagination Plugin ajax分页控件
<html> <body> <div id="datagrid"> </div> <div id="paginati ...
- poj2070简单题
#include <stdio.h> #include <stdlib.h> int main() { float sped; int wei,sth; while(scanf ...
- 基于Qt的图像采集系统
硬件 Point Gray Camera 型号:FL3-U3-13S2C-CS 参数 Sony IMX035 CMOS, 1/3", 3.63 µm Rolling Shutter 1328 ...
- 07.31 zepto
tag事件 viewport标签 flexbox弹性布局 响应式布局 rem 交互优化 touchstart touchend 高清图片 1px 单文本溢出 多文本溢出