Luogu P1280 尼可的任务(dp)
题意:
时间为n,有k个任务,每个任务有一个开始时间和持续时间,从第一分钟开始,如果有开始的任务就要做,问最大空闲时间
n,k<=1e5
思路:
设 dp[i]为i~n时间中最大空闲时间,vector v[i]保存i开始的任务,倒推即可
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>
#include<functional> #define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x)) using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const db eps = 1e-;
const int mod = 1e9+;
const int maxn = 2e3+;
const int maxm = 2e6+;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0); int n, k;
int a[maxn];
vector<int>v[maxn];
int dp[maxn];
int main(){
scanf("%d %d", &n, &k);
for(int i = ; i <= k; i++){
int x, y ;
scanf("%d %d", &x, &y);
v[x].pb(y);
}
for(int i = n; i >= ; i --){
if(v[i].size()==){
dp[i] = dp[i+]+;
}
else{
for(int j = ; j < (int)v[i].size(); j++){
dp[i] = max(dp[i+v[i][j]],dp[i]);
}
}
}
printf("%d",dp[]);
return ;
}
/**/
Luogu P1280 尼可的任务(dp)的更多相关文章
- 【Luogu】P1280尼克的任务(DP)
做顺序DP做惯了,死活没想到这是个倒序DP. f[i]表示时刻i的最大空闲时.有以下两种可能. 1.时刻i没有任务.此时f[i]=f[i+1]+1; 2.时刻i有许多任务.此时f[i]=max(f[i ...
- Luogu P1280 Niko的任务【线性dp】By cellur925
Nikonikoni~~ 题目传送门 这是当时学长讲dp的第一道例题,我还上去献了个丑,然鹅学长讲的方法我似董非董(??? 我当时说的怎么设计这道题的状态,但是好像说的是二维,本题数据范围均在1000 ...
- Luogu P4643 【模板】动态dp
题目链接 Luogu P4643 题解 猫锟在WC2018讲的黑科技--动态DP,就是一个画风正常的DP问题再加上一个动态修改操作,就像这道题一样.(这道题也是PPT中的例题) 动态DP的一个套路是把 ...
- Luogu P4643 【模板】动态dp(矩阵乘法,线段树,树链剖分)
题面 给定一棵 \(n\) 个点的树,点带点权. 有 \(m\) 次操作,每次操作给定 \(x,y\) ,表示修改点 \(x\) 的权值为 \(y\) . 你需要在每次操作之后求出这棵树的最大权独立集 ...
- luogu P2657 [SCOI2009]windy数 数位dp 记忆化搜索
题目链接 luogu P2657 [SCOI2009]windy数 题解 我有了一种所有数位dp都能用记忆话搜索水的错觉 代码 #include<cstdio> #include<a ...
- luogu -P1095 守望者的逃离 - 分别DP
P1095 守望者的逃离: https://www.luogu.org/problemnew/show/P1095 题意: 有一个人要在S长度的直线上跑过去,初始有M的魔法值,用10点魔法值可以在一秒 ...
- 题解 BZOJ1026 & luogu P2657 [SCOI2009]windy数 数位DP
BZOJ & luogu 看到某大佬AC,本蒟蒻也决定学习一下玄学的数位$dp$ (以上是今年3月写的话(叫我鸽神$qwq$)) 思路:数位$DP$ 提交:2次 题解:(见代码) #inclu ...
- BZOJ 2669 Luogu P3160 [CQOI2012]局部极小值 (容斥原理、DP)
题目链接 (bzoj) https://www.lydsy.com/JudgeOnline/problem.php?id=2669 (luogu) https://www.luogu.org/prob ...
- [luogu]P3959 宝藏[NOIP][状态压缩DP]
[luogu]P3959 宝藏[TREASURE] 题目描述 参与考古挖掘的小明得到了一份藏宝图,藏宝图上标出了 n 个深埋在地下的宝藏屋, 也给出了这 n 个宝藏屋之间可供开发的 m 条道路和它们的 ...
随机推荐
- Arrays.asList 返回值类型
public static void main(String[] args) { Integer[] datas = {1,2,3,4,5}; List<Integer> list = A ...
- CF854C Planning优先队列|set
C. Planning 传送门 Helen works in Metropolis airport. She is responsible for creating a departure sched ...
- 升级添加到现有iOS Xcode项目的Flutter
如果你在2019年8月之前将Flutter添加到现有iOS项目,本文值得你一看. 在2019年7月30日,合并合并请求flutter / flutter#36793之前Flutter 1.8.4-pr ...
- python列表(数组)
列表(list) 就是 数组 - 列表是Python中的一个对象 - 对象(object)就是内存中专门用来存储数据的一块区域 - 之前我们学习的对象,像数值,它只能保存一个单一的数据 - 列表中可 ...
- 容器环境的JVM内存设置最佳实践
Docker和K8S的兴起,很多服务已经运行在容器环境,对于java程序,JVM设置是一个重要的环节.这里总结下我们项目里的最佳实践. Java Heap基础知识 默认情况下,jvm自动分配的heap ...
- Jquery电子签名制作_jSignature
今天用Jquery的jSignature库制作一个电子签名 后台.net core上传到指定文件夹 下载jquery库 提取码:rd9g html @{ Layout = null; } <!D ...
- @Controller和@RestController
@RestController=@Controller+@ResponseBody 1.使用RestController时,返回到前端的内容是Return里的内容,无法返回jsp/html等页面, 此 ...
- Jenkins 应用
一.Jenkins Linux shell集成 新建任务 shell-freestyle-job,选择Freestyle project,点击[确定] 添加描述,This is my first ...
- NumPy排序
numpy.sort()函数 该函数提供了多种排序功能,支持归并排序,堆排序,快速排序等多种排序算法 使用numpy.sort()方法的格式为: numpy.sort(a,axis,kind,orde ...
- Nmap使用教程(进阶篇)
什么是防火墙? 防火墙是用来控制网络访问的软件或硬件.分为以下两类:1.基于主机的防火墙:2.基于网络的防火墙. 基于主机的防火墙 这是在单台主机上运行的软件,用来控制入站流量(从网络向主机)和出站流 ...