最长递增子序列 dp

 

 

/*
    Name:
    Copyright:
    Author:  流照君
    Date: data
    Description:
*/
#include <iostream>
#include<string>
#include <algorithm>
#include <vector>
#define inf 0x3f3f
using namespace std;
typedef long long ll;
int main()
{
	//freopen("in.txt", "r", stdin);
	int n,a[inf],dp[inf];
	fill(dp,dp+inf,0);
	cin>>n;
	for(int i=0;i<n;i++)
	cin>>a[i];
	dp[0]=1;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<i;j++)
		{
			if(a[i]>=a[j])
			{
				dp[i]=max(dp[i],dp[j]+1); 
			}
		}
	}
	ll maxx=1;
	for(int i=0;i<n;i++)
	{
		if(dp[i]>maxx)
		maxx=dp[i];
	}
	cout<<maxx<<endl;
    //freopen("out.txt", "w", stdout);
    return 0;
}

  思想

 

 

好久没写题目了,惭愧

posted @ 2019-12-17 16:32  流照君  阅读(203)  评论(0编辑  收藏  举报