hdu 5256 序列变换(LIS最长上升子序列)

时间:2023-03-09 23:12:37
hdu 5256 序列变换(LIS最长上升子序列)
Problem Description
我们有一个数列A1,A2...An,你现在要求修改数量最少的元素,使得这个数列严格递增。其中无论是修改前还是修改后,每个元素都必须是整数。
请输出最少需要修改多少个元素。
Input
第一行输入一个T(≤T≤),表示有多少组数据

每一组数据:

第一行输入一个N(≤N≤),表示数列的长度

第二行输入N个数A1,A2,...,An。

每一个数列中的元素都是正整数而且不超过106。
Output
对于每组数据,先输出一行
Case #i:

然后输出最少需要修改多少个元素。
Sample Input

Sample Output
Case #:
Case #:
Source

LIS最长上升子序列裸题

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<cmath>
using namespace std;
int n;
int a[];
int b[];
int LIS()
{
int cnt=;
for(int i=;i<n;i++)
{
int t=upper_bound(b,b+cnt,a[i])-b;
b[t]=a[i];
if(t==cnt) cnt++;
}
return cnt;
}
int main()
{
int t;
int ac=;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
int m=;
for(int i=;i<=n;i++)
{
int x;
scanf("%d",&x);
a[m++]=x-i;
}
printf("Case #%d:\n",++ac);
printf("%d\n",n-LIS());
}
return ;
}