码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-09-11 22:14:39      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:

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

 

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

标签:

原文地址:http://www.cnblogs.com/UniqueColor/p/4802100.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!