码迷,mamicode.com
首页 > 其他好文 > 详细

Luogu1280 尼克的任务

时间:2018-05-27 12:06:36      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:ace   std   scan   int   line   const   long   IV   fine   

不看题解真的不会做

\(f[i]\)表示最大空闲时间

但是要逆推

方程

\(if(b[i]==0)ans[i]=ans[i+1]+1;\)

\(if(ans[i+a[q].t]>ans[i])ans[i]=ans[i+a[q].t];\)

#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const ll mx=10010;

ll n,k,q=1;
ll b[mx],ans[mx];
struct node{ll p,t;}a[mx];

bool cmp(node a,node b) { return a.p>b.p; }
int main(){
    scanf("%lld %lld",&n,&k);
    for(ll i=1;i<=k;i++)
        scanf("%lld %lld",&a[i].p,&a[i].t),b[a[i].p]++;
    sort(a+1,a+k+1,cmp);
    for(ll i=n;i>0;i--){
        if(b[i]==0)ans[i]=ans[i+1]+1;
        else{
            for(ll j=1;j<=b[i];j++){
                if(ans[i+a[q].t]>ans[i])ans[i]=ans[i+a[q].t];
                q++;
            }
        }
    }

    printf("%lld",ans[1]);
    return 0;
}

Luogu1280 尼克的任务

标签:ace   std   scan   int   line   const   long   IV   fine   

原文地址:https://www.cnblogs.com/pushinl/p/9095233.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!