[ CodeVS冲杯之路 ] P1576

  不充钱,你怎么AC?

  题目:http://codevs.cn/problem/1576/

  这和上一道题十分的类似,所以直接秒杀 ( 上一题:http://www.cnblogs.com/hadilo/p/5865216.html )

  设 f[i] 为在第 i 个数字时 最长上升序列的个数

  

  目标状态为 max(f[i])

 1 #include<algorithm>
 2 #include<iostream>
 3 #include<cstdlib>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<cmath>
 7 #define N 5001
 8 using namespace std;
 9 
10 int a[N],f[N],n,ans;
11 int main()
12 {
13     int i=0,j;
14     scanf("%d",&n);
15     for (i=1;i<=n;i++) scanf("%d",&a[i]);
16     for (i=1;i<=n;i++)
17     {
18         for (j=0;j<i;j++)
19         {
20             if (a[j]<a[i])
21             {
22                 if (f[i]<f[j]+1)
23                 {
24                     f[i]=f[j]+1;
25                     ans=max(ans,f[i]);
26                 }
27             }
28         }
29     }
30     printf("%d
",ans);
31     return 0;
32 }
原文地址:https://www.cnblogs.com/hadilo/p/5865403.html