2020牛客暑期多校训练营(第五场)D.Drop Voicing

题目链接

思路:

求循环链的最大上升子序列。

代码:

#include
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N=1010;
const int M=4e5+8;
const double eps=1e-8;
const int mod=1e9+7;
const int inf=0x7fffffff;
const double pi=3.1415926;
int a[N],d[N],n,ans;
int LIS(int l,int r)
{
	d[1]=a[l];
	int len=1;
	for (int i=l+1;i<=r;i++)
    {
		if(a[i]>=d[len])
		{
		    d[++len]=a[i]; 
		}
		else
        {
            d[upper_bound(d+1,d+len+1,a[i])-d]=a[i];
        }
	}
	return len;
}
signed main()
{
    IOS;
    int n;
	cin>>n;
	for (int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
	for (int i=1;i<=n;i++)
    {
        a[n+i]=a[i];
    }
	for (int i=1;i<=n;i++)
    {
        ans=max(ans,LIS(i,i+n-1));
    }
	cout<<n-ans<<endl;
	return 0;
}

你可能感兴趣的:(思维)