Problem Solving P1280 [Nick's Mission]

f[i] represents the longest idle time of i~n;

If there is no current task, take a rest for one second (f[i]=f[i+1]+1);

otherwise f[i]=max(f[i],f[i+current working time]);

Using the structure to record, we open an array for each moment to store all the tasks starting at this moment, and the subscript 0 represents the number of elements in the array, which is easy to traverse:

#include<iostream>//简短的30行代码
#include<cstdio>
#include<algorithm>
#include<cstdio>
using namespace std;
int n,k,f[10010];
struct cym{
    int num[10010];
}a[10010];
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=k;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        a[x].num[ ++a[x].num[ 0 ]]= y;
    }
    for(int i=n;i>=0;i--)
    {
        if(!a[i].num[0])
        {
            f[i]=f[i+1]+1;
            continue;
        }
        for(int j=1;j<=a[i].num[0];j++)
        f[i]=max(f[i],f[i+a[i].num[j]]);
    }
    printf("%d",f[1]);
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325688848&siteId=291194637