P1799 数列_NOI导刊2010提高(06)

P1799 数列_NOI导刊2010提高(06)
f[i][j]表示前i个数删去j个数得到的最大价值。
if(i-j==x)
f[i][j]=max(f[i][j],f[i-1][j]+1);
else
f[i][j]=max(f[i][j],f[i-1][j]);
f[i][j]=max(f[i-1][j-1],f[i][j]);

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<queue>
 4 #include<algorithm>
 5 #include<cmath>
 6 #include<ctime>
 7 #include<set>
 8 #include<cstring>
 9 #define inf INT_MAX
10 #define For(i,a,b) for(register int i=a;i<=b;i++)
11 #define p(a) putchar(a)
12 #define g() getchar()
13 //by war
14 //2017.10.26
15 using namespace std;
16 int a[1010];
17 int f[1010][1010];
18 int x;
19 int ans;
20 int n;
21 void in(int &x)
22 {
23     int y=1;
24     char c=g();x=0;
25     while(c<'0'||c>'9')
26     {
27     if(c=='-')
28     y=-1;
29     c=g();
30     }
31     while(c<='9'&&c>='0')x=x*10+c-'0',c=g();
32     x*=y;
33 }
34 void o(int x)
35 {
36     if(x<0)
37     {
38         p('-');
39         x=-x;
40     }
41     if(x>9)o(x/10);
42     p(x%10+'0');
43 }
44 int main()
45 {
46     in(n);
47     For(i,1,n)
48      {
49      in(x);
50       For(j,0,i-1)
51         {
52         if(i-j==x)
53         f[i][j]=max(f[i][j],f[i-1][j]+1);
54         else
55         f[i][j]=max(f[i][j],f[i-1][j]);
56         f[i][j]=max(f[i-1][j-1],f[i][j]);
57         } 
58      }
59      For(i,0,n-1)
60      ans=max(ans,f[n][i]);
61      o(ans);
62      return 0;
63 }

 

posted @ 2017-10-27 11:13  WeiAR  阅读(153)  评论(0编辑  收藏  举报