Codeforces 1203F2. Complete the Projects (hard version)
首先对于 $b>0$ 的工作显然有个贪心,把 $b>0$ 的按 $a$ 从小到大排序
把能做的都做了,然后得到一个最大等级
剩下就是考虑 $b<0$ 的工作了,看到数据显然可以 $O(nr)$ 考虑 $dp$,设 $f[i][j]$ 表示考虑完前 $i$ 个工作,当前等级为 $j$ 时能完成的最大工作数
然后发现这样搞有点问题,因为工作考虑的顺序是会影响到最终答案的,可能先做后面的工作再来做前面的工作可以做两个,但是如果先做前面的再做后面的可能会发现等级不够了...
考虑给所有工作确定一个顺序,使得如果先做 $2$ 不能做 $1$ ,并且先做 $1$ 可以做 $2$ ,则把 $1$ 排在 $2$ 前面考虑
设 $x+b_2<a_1$,$x+b1>=a2$ (注意这里 $b<0$),那么有 $x<a_1-b_2,x>=a_2-b_1$,即 $a_2-b_1<a_1-b_2$
所以排序时根据 $a_1-b_2$ 从大到小排序即可
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=,M=;
int n,m;
struct dat {
int a,b;
dat (int _a=,int _b=) { a=_a,b=_b; }
inline bool operator < (const dat &tmp) const {
return a-tmp.b>tmp.a-b;
}
};
vector <dat> C,D;
inline bool cmp(const dat &A,const dat &B) { return A.a<B.a; }
int ans,f[N][M];
int main()
{
n=read(),m=read(); int a,b;
for(int i=;i<=n;i++)
{
a=read(),b=read();
if(b<) D.push_back(dat(a,b));
else C.push_back(dat(a,b));
}
sort(C.begin(),C.end(),cmp); sort(D.begin(),D.end());
for(auto A: C) if(m>=A.a) m+=A.b,ans++;
memset(f,~0x3f,sizeof(f)); f[][m]=;
int len=D.size(),res=;
for(int i=;i<=len;i++)
{
for(int j=;j<=m;j++)
{
f[i][j]=f[i-][j];
if(j-D[i-].b>=D[i-].a) f[i][j]=max(f[i][j],f[i-][j-D[i-].b]+);
res=max(res,f[i][j]);
}
}
printf("%d\n",ans+res);
return ;
}
Codeforces 1203F2. Complete the Projects (hard version)的更多相关文章
- Codeforces 1203F1 Complete the Projects (easy version)
cf题面 Time limit 2000 ms Memory limit 262144 kB 解题思路 看见这题觉得贪心可做,那就贪吧.(昨天真是贪心的一天,凌晨才被这两道贪心题虐,下午多校又来,感觉 ...
- CF1203F2 Complete the Projects (hard version)(结论+背包+贪心)
题目 做法 对于加分的直接贪心 而掉分的用排序后的背包动规 假设有两个物品\((a_1,b_1)(a_2,b_2)\) 选第一个物品后无法选择第二个物品,假设开始值为\(r\):\(r>a_1, ...
- Codeforces1203F2. Complete the Projects (hard version) (贪心+贪心+01背包)
题目链接:传送门 思路: 对于对rating有提升的项目,肯定做越多越好,所以把$b_{i} >= 0$的项目按rating要求从小到大贪心地都做掉,得到最高的rating记为r. 对于剩余的$ ...
- Complete the Projects
F1. Complete the Projects (easy version) F2. Complete the Projects (hard version) 参考:Complete the Pr ...
- codeforces 372 Complete the Word(双指针)
codeforces 372 Complete the Word(双指针) 题链 题意:给出一个字符串,其中'?'代表这个字符是可变的,要求一个连续的26位长的串,其中每个字母都只出现一次 #incl ...
- Codeforces Round #579 (Div. 3) Complete the Projects(贪心、DP)
http://codeforces.com/contest/1203/problem/F1 Examples input 1 - - output 1 YES input 2 - - output 2 ...
- Codeforces 716B Complete the Word【模拟】 (Codeforces Round #372 (Div. 2))
B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Round #527-D1. Great Vova Wall (Version 1)(思维+栈)
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- Codeforces 1108E2 Array and Segments (Hard version) 差分, 暴力
Codeforces 1108E2 E2. Array and Segments (Hard version) Description: The only difference between eas ...
随机推荐
- python配置文件
python有两种配置文件,file.ini和file.json 一.ini文件如下: db_config.ini [baseconf] host=127.0.0.1 port=3306 user=r ...
- 修改mp3图片和信息——BesMp3Editor
导读 BesMp3Editor, 是一款小巧的 MP3 编辑工具,可以修改.添加 MP3 上的图片.歌曲名.歌手.专辑信息. 最近想给 BesLyric-for-X 添加一个功能,为下载下来的歌曲添加 ...
- Ubuntu16 升级nodejs版本
Ubuntu16下,使用apt-get下载的nodejs最新版本为v4.2.6,而react-native需要v8.x及以上的版本 解决方法在网上找到了这一篇博客Ubuntu安装最新版nodejs,用 ...
- vue图片的处理技巧
我们想用 post 向后台发送字符串类型的数据:我们可以不适用 data 来进行数据传输,而是用 params 来进行数据传输 代码的简洁之道:分模块化书写: vue 里面提供对图片的监听事件:loa ...
- C++ STL 中 map 容器
C++ STL 中 map 容器 Map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据 处理能力,由于这个特性,它 ...
- rocketmq的linux搭建环境
3.3. 上传解压[两台机器] # 上传 apache-rocketmq.tar.gz 文件至/usr/local # tar -zxvf apache-rocketmq.tar.gz -C /usr ...
- 调用远程linux服务器shell脚本
package com.haiyisoft.hyoaPc.ui; import java.io.BufferedReader;import java.io.IOException;import jav ...
- [go]unsafe.Sizeof浅析
sizeof 如果x为一个切片,sizeof返回的大小是切片的描述符,而不是切片所指向的内存的大小. 那么这里如果换成一个数组呢?而不是一个切片 arr := [...]int{1,2,3,4,5} ...
- 小D课堂 - 新版本微服务springcloud+Docker教程_3-03CAP原理、常见面试题
笔记 3.分布式系统CAP原理常见面试题和注册中心选择 简介:讲解CAP原则在面试中回答和注册中心选择 C A 满足的情况下,P不能满足的原因: 数据同步(C) ...
- kvm简介及创建虚拟化安装(1)
kvm虚拟化介绍 一.虚拟化分类 1.虚拟化,是指通过虚拟化技术将一台计算机虚拟为多台逻辑计算机.在一台计算机上同时运行多个逻辑计算机,每个逻辑计算机可运行不同的操作系统,并且应用程序都可以在相互独立 ...