P1280 尼克的任务

 

https://www.luogu.org/problemnew/show/P1280#sub 题目

 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include <cctype>
 4 #include<algorithm>
 5 #include<cstring>
 6 #include<cmath>
 7 #include<string>
 8 #include<cmath>
 9 #include<set>
10 #include<vector>
11 #include<stack>
12 #include<queue>
13 #include<map>
14 using namespace std;
15 #define ll long long
16 #define mem(a,x) memset(a,x,sizeof(a))
17 #define se second
18 #define fi first
19 const int INF= 0x3f3f3f3f;
20 const int N=1e4+5;
21 
22 int n,k,f[N],num;
23 int a[N]={0};
24     
25 struct node
26 {
27     int l,t;
28 }q[N];
29 int main()
30 {
31     cin>>n>>k;
32     for(int i=1;i<=k;i++)
33     {
34         cin>>q[i].l>>q[i].t;
35         a[q[i].l ]++;
36     }
37     mem(f,0);
38     num=k; //从k开始,因为要倒推 
39     for(int i=n;i>=1;i--)
40     {
41         if(a[i]==0) f[i]=f[i+1]+1;  //此题倒推 
42         
43         else 
44         for(int j=1;j<=a[i]; j++)
45         {
46             f[i]= max( f[i], f[i+q[num].t ]);
47             num--;
48         }
49     }
50     cout<<f[1]<<endl;
51 }

 

posted @ 2018-08-06 14:23  木流牛马  阅读(112)  评论(0编辑  收藏  举报