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

Problem Description
我们有一个数列A1,A2...An,你现在要求修改数量最少的元素,使得这个数列严格递增。其中无论是修改前还是修改后,每个元素都必须是整数。
请输出最少需要修改多少个元素。

 

 
Input
第一行输入一个T(1≤T≤10),表示有多少组数据

每一组数据:

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

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

每一个数列中的元素都是正整数而且不超过106。

 

 

 

Output
对于每组数据,先输出一行

 

Case #i:

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

 

 

 

Sample Input
2
2
1 10
3
2 5 4

 

 

 

Sample Output
Case #1: 0 
Case #2: 1

 

 

 

Source
 

 LIS最长上升子序列裸题

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<stdlib.h>
 6 #include<cmath>
 7 using namespace std;
 8 int n;
 9 int a[100006];
10 int b[100006];
11 int LIS()
12 {
13     int cnt=0;
14     for(int i=0;i<n;i++)
15     {
16         int t=upper_bound(b,b+cnt,a[i])-b;
17         b[t]=a[i];
18         if(t==cnt) cnt++;
19     }
20     return cnt;
21 }
22 int main()
23 {
24     int t;
25     int ac=0;
26     scanf("%d",&t);
27     while(t--)
28     {
29         scanf("%d",&n);
30         int m=0;
31         for(int i=1;i<=n;i++)
32         {
33             int x;
34             scanf("%d",&x);
35             a[m++]=x-i;
36         }
37         printf("Case #%d:\n",++ac);
38             printf("%d\n",n-LIS());    
39     }
40     return 0;
41 }
View Code

 

转载于:https://www.cnblogs.com/UniqueColor/p/4802100.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值