• 求最长公共子序列的长度


     1 #include <cstdio>
     2 #include <iostream>
     3 
     4 using namespace std;
     5 
     6 const int max_n = 1000 + 2;
     7 const int max_a = 1e6 + 10;
     8 
     9 int n;
    10 int a[max_n];
    11 int dp[max_n];
    12 
    13 void solve()
    14 {
    15     for(int i=1;i<=n;++i)
    16     {
    17         dp[i]=1;
    18         for(int j=1;j<i;++j)
    19         {
    20             if(a[j]<a[i])
    21             {
    22                 dp[i]=max(dp[i],dp[j]+1);
    23             }
    24         }
    25     }
    26     printf("%d
    ",dp[n]);
    27 }
    28 
    29 int main()
    30 {
    31     scanf("%d",&n);
    32     for(int i=1;i<=n;++i)
    33     {
    34         scanf("%d",&a[i]);
    35     }
    36     solve();
    37     return 0;
    38 }
    39 
    40 /*test
    41 5
    42 4 2 3 1 5
    43 
    44 */
  • 相关阅读:
    Scala--基础
    maven
    Storm 运行例子
    Storm 安装部署
    Storm
    Kafka 集群部署
    Redis Twemproxy
    Redis Sentinel
    获取URL中参数的值
    浏览器滚动条样式
  • 原文地址:https://www.cnblogs.com/jishuren/p/12259571.html
Copyright © 2020-2023  润新知