您的位置:首页 > 其它

hdu 6197 array array array LIS

2017-09-13 12:13 288 查看
正反跑一次LIS,取最大的长度,如果长度大于n-k就满足条件。

ac代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <map>
#include <stack>
#include <algorithm>
using namespace std;
int dp[1001];
int LIS(int a[],int len)
{
int ret=0;
memset(dp,0,sizeof(dp));
for(int i=1;i<=len;i++)
{
if(a[i] > dp[ret]) dp[++ret]=a[i];
else
{
int pos=lower_bound(dp+1,dp+ret,a[i])-dp;
dp[pos]=a[i];
}
}
return ret;
}
int b[100010],c[100010];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,k;
scanf("%d %d",&n,&k);
int pos=n-1;
for(int i=1;i<=n;i++)
{
scanf("%d",&b[i]);
c[pos--]=b[i];
}
int mx=max(LIS(c,n),LIS(b,n));
if(n-mx<=k) cout<<"A is a magic array."<<endl;
else cout<<"A is not a magic array."<<endl;
}
return 0;
}


心情不太好,过来这么久才整理代码。 感情这个东西,比算法难多了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: