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 ...
随机推荐
- ORACLE 两个表或两个结果集的数据对比常用的函数
假设有两个表A,B,都只有一个字段PHONE 1,MINUS SELECT PHONE FROM A MINUS SELECT PHONE FROM B; 相当于用结果集A减去结果B得出的结果 ...
- 查看oracle数据库的大小和空间使用情况
查看oracle数据库的大小和空间使用情况 (2012-06-19 14:44:30) 转载▼ 标签: 杂谈 分类: oracle 1.查看表空间的使用状况 SELECT upper(f.tables ...
- Autoconf/Automake工具简介
在linux下编程的时候,有时候工程项目很大,文件比较多,此时需要使用自动创建Makefile文件功能.也就是使用Autoconf/Automake工具自动生成Makefile,为编译程序带来了方便, ...
- [LeetCode][Python]Regular Expression Matching
# -*- coding: utf8 -*-'''https://oj.leetcode.com/problems/regular-expression-matching/ Implement reg ...
- iOS获取手机当前的网络状态
获取iOS网络状态,目前有两个办法. 1.通过监听手机状态栏的信息. 2.通过使用官方提供的类Reachability. 一.通过手机监听手机状态栏的信息 好处: 1.可以通过苹果的审核上架AppSt ...
- css3幻灯片换位效果
<title>css3幻灯片换位效果</title> <style type="text/css"> .flowGallery {width: ...
- SET ANSI_NULLS (Transact-SQL)
指定在 SQL Server 2014 中与 Null 值一起使用等于 (=) 和不等于 (<>) 比较运算符时采用符合 ISO 标准的行为. 当 SET ANSI_NULLS 为 ON ...
- IE 对象不支持“attachEvent”属性或方法
解决方法:attachEvent 是很旧的非标准方法.请使用 addEventListener.
- AngularJS ng-class用法
mark from https://my.oschina.net/gejiawen0913/blog/188547 ng-class是AngularJS预设的一个指令,用于动态自定义dom元素的css ...
- wp8.1开发系列之安装包URI方案
应用文件使用"ms-appdata:///"开头的URI地址,安装包使用的是"ms-appx:///"开头的URI地址. 比如:读取安装包Image文件夹下的t ...