hdu 1087 Super Jumping! Jumping! Jumping! (最大 上升子序列 线性 dp)
http://acm.hdu.edu.cn/showproblem.php?pid=1087
题意: 求最大上升子序列 。。。。
1 #include<cstdio>
2 #include<cstring>
3 #include<cmath>
4 #include<iostream>
5 #include<algorithm>
6 #include<set>
7 #include<map>
8 #include<queue>
9 #include<vector>
10 #include<string>
11 #define Min(a,b) a<b?a:b
12 #define Max(a,b) a>b?a:b
13 #define CL(a,num) memset(a,num,sizeof(a));
14 #define maxn 1100
15 #define eps 1e-6
16 #define inf 9999999
17 #define read() freopen("data.in","r",stdin) ;
18 using namespace std;
19 int a[maxn] ;
20 int dp[maxn] ;
21 int main()
22 {
23 int n , m ;
24 int ans ,i,j;
25 //read() ;
26 while(scanf("%d",&n),n)
27 {
28 ans = -inf;
29 for(i = 0 ; i < n;i++)
30 {
31 scanf("%d",&a[i]) ;
32 }
33 CL(dp, 0) ;
34 for(i = 0 ; i< n;i++) dp[i] = a[i] ;
35 for(i = 1 ; i < n;i++)
36 {
37 for(j = i - 1; j >= 0;j -- )
38 {
39 if(a[i] > a[j])
40 {
41 dp[i] = max(dp[i],dp[j] + a[i]) ;
42
43 }
44 }
45 if(ans < dp[i]) ans = dp[i] ;
46 }
47 printf("%d\n",ans) ;
48 }
49 }
2 #include<cstring>
3 #include<cmath>
4 #include<iostream>
5 #include<algorithm>
6 #include<set>
7 #include<map>
8 #include<queue>
9 #include<vector>
10 #include<string>
11 #define Min(a,b) a<b?a:b
12 #define Max(a,b) a>b?a:b
13 #define CL(a,num) memset(a,num,sizeof(a));
14 #define maxn 1100
15 #define eps 1e-6
16 #define inf 9999999
17 #define read() freopen("data.in","r",stdin) ;
18 using namespace std;
19 int a[maxn] ;
20 int dp[maxn] ;
21 int main()
22 {
23 int n , m ;
24 int ans ,i,j;
25 //read() ;
26 while(scanf("%d",&n),n)
27 {
28 ans = -inf;
29 for(i = 0 ; i < n;i++)
30 {
31 scanf("%d",&a[i]) ;
32 }
33 CL(dp, 0) ;
34 for(i = 0 ; i< n;i++) dp[i] = a[i] ;
35 for(i = 1 ; i < n;i++)
36 {
37 for(j = i - 1; j >= 0;j -- )
38 {
39 if(a[i] > a[j])
40 {
41 dp[i] = max(dp[i],dp[j] + a[i]) ;
42
43 }
44 }
45 if(ans < dp[i]) ans = dp[i] ;
46 }
47 printf("%d\n",ans) ;
48 }
49 }