codeforces 480D
题意:给定一些物品放置在承重为S的桌子上, 每个物品有5个属性,放置时间in,拿开时间out,重量w,承重s及放置后的收益v。而且后面放置上去的必须先拿开。。求一种合法的放置使得收益最大,输出收益。
思路:先对所有的物品按照out递增,out相同l递减的情况排序。
那么很容易想到dp。。
f[i][j]表示放置了第i个,还可承重j的最大收益(i本身还没算)。
把(in[i], out[i])看成线段
那么,等价于(in[i], out[i])之间找出最多不相交线段。
这个可以用记忆化搜索,当然也可以非递归。。
具体看代码应该比较容易懂吧。。
code:
#include <bits/stdc++.h>
using namespace std;
struct oo{
int l, r, w, s, v;
void input(){
scanf("%d%d%d%d%d", &l, &r, &w, &s, &v);
}
bool operator<(const oo& p) const{
return r < p.r || (r == p.r && l > p.l);
}
} a[];
int n, s, f[][], tmp[];
void solve(){
a[] = (oo){, n*, , s, };
for (int i = ; i <= n; ++i) a[i].input();
sort(a, a + n + );
int cur, s1;
for (int i = ; i <= n; ++i)
for (int j = a[i].w; j <= s; ++j){
tmp[cur = a[i].l] = ;
s1 = min(j-a[i].w, a[i].s);
for (int k = ; k < i; ++k) if (a[k].l >= a[i].l){
for (;cur<a[k].r;)
++cur, tmp[cur] = tmp[cur-];
tmp[cur] = max(tmp[cur], tmp[a[k].l] + f[k][s1]);
}
f[i][j] = tmp[cur] + a[i].v;
}
cout << f[n][s] << endl;
} int main(){
// freopen("a.in", "r", stdin);
while (scanf("%d%d", &n, &s) != EOF){
solve();
}
}
codeforces 480D的更多相关文章
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
- CodeForces - 148D Bag of mice
http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...
随机推荐
- SNP(单核苷酸多态性)准确性的验证,你造吗?
SNP(单核苷酸多态性)准确性的验证,你造吗? [2016-12-12] SNP(全称Single Nucleotide Polymorphisms)即单核苷酸多态性,主要是指在基因组水平 ...
- Python 中docx转pdf
#第一种import comtypes.clientdef convertDocxToPDF(infile,outfile): wdFormatPDF = 17 word = comtypes.cli ...
- Trapping Rain Water LT42
The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of ...
- android 使用webview 加载网页
1. <WebView android:id="@+id/webView" android:layout_width="fill_parent" andr ...
- 【NIFI】 实现数据库到数据库之间数据同步
本里需要基础知识:[NIFI] Apache NiFI 安装及简单的使用 数据同步 界面如下: 具体流程: 1.使用ExecuteSQL连接mysql数据库,通过写sql查询所需要的数据 2.nifi ...
- HTML and CSS学习概述-续
1, CSS是层叠样式表(Cascading Style Sheets)的缩写,它用于定义HTML元素的显示形式,是一种格式化网页内容的技术.CSS现在已经被大多数浏览器所支持,成为网页设计者必须 ...
- Django框架之Ajax和form组件
一.Django框架之查漏补缺 1)models,字段概况 name = models.CharField(max_length=) age = models.IntegerField() price ...
- zookeeper集群的搭建(三台相同)
查看jdk java -version 卸载自带jdk rpm -qa|grep java rpm -e --nodeps tzdata-java-2015e-1.el6.noarch rpm -e ...
- C++中栈和队列的基本操作
栈操作: s.push(item) // 将item压入栈中 s.pop() // 删除栈顶元素,不返回值 s.top() // 读取栈顶元素,返回 ...
- 机器学习笔试--LeetCode
#########简单######### 共25道: 1. 两数之和 给定一个整数数组和一个目标值,找出数组中和为目标值的两个数. 你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用. 示例 ...