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

P1280 尼克的任务

时间:2019-09-30 21:51:51      阅读:91      评论:0      收藏:0      [点我收藏+]

标签:space   ble   node   name   需要   int   string   sort   names   

题面:https://www.luogu.org/problem/P1280

本题唯一需要注意的是要倒序枚举,因为若正序枚举的话,在转移i的时候还没有转移i+t,所以只能倒序转移.

Code:
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=10005;
int n,k,sum[N],f[N];
struct Node{
    int st,last;  
}work[N];  
int cmp(Node a,Node b){ 
    return a.st>b.st;  
}
int main() {
    long int i,j;   
    scanf("%d%d",&n,&k);
    for(i=1;i<=k;i++){
        scanf("%d%d",&work[i].st,&work[i].last);
        sum[work[i].st]++;
    }  
    sort(work+1,work+1+k,cmp);
    int num=1;
    for(i=n;i>=1;i--){
        if(sum[i]==0){
            f[i]=f[i+1]+1;
        }
        else{
            for(j=1;j<=sum[i];j++){
                if(f[i+work[num].last]>f[i]){
                    f[i]=f[i+work[num].last];
                }
                num++;
            }
        }
    }
    printf("%d\n",f[1]);
    return 0;
}

P1280 尼克的任务

标签:space   ble   node   name   需要   int   string   sort   names   

原文地址:https://www.cnblogs.com/ukcxrtjr/p/11614114.html

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