标签:
Description
Input
Output
Sample Input
7 1 7 3 5 9 4 8
Sample Output
4
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <queue> #include <vector> #include <iomanip> #include <math.h> #include <map> using namespace std; #define FIN freopen("input.txt","r",stdin); #define FOUT freopen("output.txt","w",stdout); #define INF 0x3f3f3f3f #define INFLL 0x3f3f3f3f3f3f3f #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 typedef long long LL; typedef pair<int,int> PII; int a[1005]; int dp[1005]; int main() { //FIN int n; scanf("%d", &n); int m; dp[1] = 1; for(int i = 1; i <= n; i ++) scanf("%d", &a[i]); for(int i = 2; i <= n;i ++){ m = 0; for(int j = 1; j <= i-1; j ++){ if(a[j] < a[i] && dp[j] > m){ //在前i-1中,找出终点小于dp[i]的最长的子序列 m = dp[j]; } } dp[i] = m + 1; } sort(dp + 1, dp +1 +n); printf("%d", dp[n]); }
OpenJudge Bailian 2757 最长上升子序列 DP
标签:
原文地址:http://www.cnblogs.com/Hyouka/p/5778386.html