【题解】洛谷P1280尼克的任务 线性DP
设 表示 以 时间开始的最长休息时间。
初值 目标
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=10010;
int now,f[N],n,k;
struct node{
int p,t;
bool operator<(const node&rhs)const{
return p<rhs.p;}
}w[N];
int main()
{
//freopen("in.txt","r",stdin);
scanf("%d%d",&n,&k);now=k;
for(int i=1;i<=k;i++)
scanf("%d%d",&w[i].p,&w[i].t);
sort(w+1,w+k+1);
for(int i=n;i;i--)
{
bool free=1;
while(w[now].p==i)f[i]=max(f[i],f[i+w[now--].t]),free=0;
if(free)f[i]=f[i+1]+1;
}
printf("%d\n",f[1]);
return 0;
}
总结
无