生活随笔
收集整理的這篇文章主要介紹了
P1799 数列_NOI导刊2010提高(06)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
P1799 數(shù)列_NOI導刊2010提高(06)
f[i][j]表示前i個數(shù)刪去j個數(shù)得到的最大價值。
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 }
?
轉(zhuǎn)載于:https://www.cnblogs.com/war1111/p/7742228.html
總結(jié)
以上是生活随笔為你收集整理的P1799 数列_NOI导刊2010提高(06)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。