hdu 6197 array array array LIS
2024-09-01 14:20:39
正反跑一次LIS,取最大的长度,如果长度大于n-k就满足条件。
ac代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <map>
#include <stack>
#include <algorithm>
using namespace std;
int dp[];
int LIS(int a[],int len)
{
int ret=;
memset(dp,,sizeof(dp));
for(int i=;i<=len;i++)
{
if(a[i] > dp[ret]) dp[++ret]=a[i];
else
{
int pos=lower_bound(dp+,dp+ret,a[i])-dp;
dp[pos]=a[i];
}
}
return ret;
}
int b[],c[];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,k;
scanf("%d %d",&n,&k);
int pos=n-;
for(int i=;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;
}
心情不太好,过来这么久才整理代码。 感情这个东西,比算法难多了
最新文章
- java.lang.reflect.Field
- Libevent 定时器
- BestCoder Round #86 部分题解
- BZOJ1634: [Usaco2007 Jan]Protecting the Flowers 护花
- Java 多线程 笔记 转自http://www.cnblogs.com/lwbqqyumidi/p/3804883.html
- 微信小程序开发之微信支付
- Java多线程之赛跑游戏
- $(this) 和 this 关键字在 jquery 中有何不同?
- Go Example--工作池
- 关于zynq7 中MIO的理解
- [转载]java开发中的23种设计模式
- OWASP TOP10(2017)
- Python glob.md
- (纪录片)《星际穿越》中的科学 The Science of Interstellar
- 基于jQuery CSS3鼠标点击动画效果
- 闲:测试memcpy和std::copy vector之间拷贝
- H.264:FFMpeg 实现简单的播放器
- Java 设计模式系列(二三)访问者模式(Vistor)
- Shiro框架简介
- LeetCode Best Time to Buy and Sell Stock with Transaction Fee