POJ-2533.Longest Ordered Subsequence (LIS模版题)

Posted bianjunting

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了POJ-2533.Longest Ordered Subsequence (LIS模版题)相关的知识,希望对你有一定的参考价值。

  本题大意:和LIS一样

  本题思路:用dp[ i ]保存前 i 个数中的最长递增序列的长度,则可以得出状态转移方程dp[ i ] = max(dp[ j ] + 1)(j < i)

  参考代码:

技术图片
 1 #include <iostream>
 2 #include <cstring>
 3 #include <algorithm>
 4 using namespace std;
 5 
 6 const int maxn = 1e3 + 5;
 7 int a[maxn], dp[maxn];
 8 
 9 int main () {
10     int n, ans = 0;
11     cin >> n;
12     for(int i = 1; i <= n; i ++)
13         cin >> a[i];
14     for(int i = 1; i <= n; i ++) {
15         dp[i] = 1;
16         for(int j = 1; j < i; j ++) {
17             if(a[i] > a[j]) dp[i] = max(dp[i], dp[j] + 1);
18         }
19         ans = dp[i] > ans ? dp[i] : ans;
20     }
21     cout << ans << endl;
22     return 0;
23 }
View Code

 

以上是关于POJ-2533.Longest Ordered Subsequence (LIS模版题)的主要内容,如果未能解决你的问题,请参考以下文章

POJ2533:Longest Ordered Subsequence

POJ 2533 Longest Ordered Subsequence

poj 2533 Longest Ordered Subsequence(LIS)

POJ 2533 Longest Ordered Subsequence(裸LIS)

POJ 2533 Longest Ordered Subsequence DP

POJ - 2533 Longest Ordered Subsequence