序列变换

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 820    Accepted Submission(s): 336

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
分析:找出的最长上升子序列a[i]-a[j]>=i-j;把a[i]-=i;之后的值按照非严格递增最长子序列的值L,最后n-L就是要改变的最小值
程序:
 #include"stdio.h"
#include"string.h"
#include"stdlib.h"
#include"algorithm"
#include"queue"
#include"math.h"
#include"iostream"
#include"vector"
#define M 100009
#define inf 0x3f3f3f3f
#define eps 1e-9
#define PI acos(-1.0)
#include"map"
#include"vector"
#include"set"
#include"string"
#include"stack"
#define LL __int64
using namespace std;
int a[M],b[M],c[M];
int finde(int n,int k)
{
int l=;
int r=n;
while(l<=r)
{
int mid=(l+r)/;
if(c[mid]<=k)
l=mid+;
else
r=mid-;
}
return l;
}
int main()
{
int n;
int T,kk=;
cin>>T;
while(T--)
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
a[i]-=i;
} memset(c,inf,sizeof(c));
b[]=;
c[]=a[];
for(int i=;i<=n;i++)
{
int id=finde(n,a[i]);
b[i]=id;
c[id]=a[i];
}
printf("Case #%d:\n",kk++);
int maxi=;
for(int i=;i<=n;i++)
maxi=max(maxi,b[i]);
printf("%d\n",n-maxi);
}
return ;
}
 #include"stdio.h"
#include"string.h"
#include"stdlib.h"
#include"algorithm"
#include"queue"
#include"math.h"
#include"iostream"
#include"vector"
#define M 100009
#define inf 0x3f3f3f3f
#define eps 1e-9
#define PI acos(-1.0)
#include"map"
#include"vector"
#include"set"
#include"string"
#include"stack"
#define LL __int64
using namespace std;
int a[M],b[M],n;
int finde()
{
int t=;
b[t]=a[];
t++;
for(int i=;i<=n;i++)
{
int id=upper_bound(b,b+t,a[i])-b;
if(id==t)
t++;
b[id]=a[i];
}
return t;
}
int main()
{
int T,kk=;
cin>>T;
while(T--)
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
a[i]-=i;
}
int leng=finde();
printf("Case #%d:\n%d\n",kk++,n-leng); }
}

最长上升子序列的变形(N*log(N))hdu5256的更多相关文章

  1. DP专辑之最长公共子序列及其变形

    vijos1111(裸的最长公共子序列) 链接:www.vijos.org/p/1111 题解:好久没有写最长公共子序列了,这题就当是复习了.求出最长公共子序列,然后用两个单词的总长度减去最长公共子序 ...

  2. hdu5282 最长公共子序列的变形

    pid=5282">http://acm.hdu.edu.cn/showproblem.php?pid=5282 Problem Description Xuejiejie loves ...

  3. Bridging signals---hdu1950(最长上升子序列复杂度n*log(n) )

     题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1950 一直只知道有除n*n的算法之外的求LIS,但是没学过,也没见过,今天终于学了一下,dp[i]表 ...

  4. ZOJ3519-Beautiful People:最长上升子序列的变形

    Beautiful People Special JudgeTime Limit: 10000/5000MS (Java/Others)Memory Limit: 128000/64000KB (Ja ...

  5. 最长上升子序列(LIS)的n*log(n)求法

    方法: 对于某个序列,设一个数组,将序列第一个数放入,然后再一个一个判断序列下一位,如果大于当前数组的末尾元素,则加入数组,否则利用二分法找到第一个大于等于当前数的元素并替换,最后这个数组的长度len ...

  6. HDU 1080 Human Gene Functions - 最长公共子序列(变形)

    传送门 题目大意: 将两个字符串对齐(只包含ACGT,可以用'-'占位),按照对齐分数表(参见题目)来计算最后的分数之和,输出最大的和. 例如:AGTGATG 和 GTTAG ,对齐后就是(为了表达对 ...

  7. hdu1503 最长公共子序列变形

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1503 题意:给出两个字符串 要求输出包含两个字符串的所有字母的最短序列.注意输出的顺序不能 ...

  8. ACM: 强化训练-Beautiful People-最长递增子序列变形-DP

    199. Beautiful People time limit per test: 0.25 sec. memory limit per test: 65536 KB input: standard ...

  9. hdu 1080 dp(最长公共子序列变形)

    题意: 输入俩个字符串,怎样变换使其所有字符对和最大.(字符只有'A','C','G','T','-') 其中每对字符对应的值如下: 怎样配使和最大呢. 比如: A G T G A T G -  G ...

随机推荐

  1. data abstractions 数据抽象

    Computer Science An Overview _J. Glenn Brookshear _11th Edition In this chapter we investigate how d ...

  2. JS基础语法

    1.注释语法://单行注释./*多行注释*/. 2.输出语法:{1.alert("要输出的字符串"):.alert(输出其类型):  2.confirm():弹出一个可以和用户交互 ...

  3. Qt中sleep()的实现(耳目一新的两种方法)

    在Qt中并没有Sleep函数可以调用,在程序编写时往往需要休眠几秒,这里举出两个方法,不知道是否啥不良隐患没~~ 方法一: class SleeperThread : public QThread{p ...

  4. 使用VC2005编译真正的静态Qt程序

    首先,你应该该知道什么叫静态引用编译.什么叫动态引用编译.我这里只是简单的提提,具体的可以google一下. 动态引用编译,是指相关的库,以dll的形式引用库.动态编译的Exe程序尺寸比较小,因为相关 ...

  5. 转:VS2010调试NUnit测试项目 (Running or debugging NUnit tests from Visual Studio without any extensions)

    If you write unit tests and use NUnit test framework this may be helpful. I decided to write this si ...

  6. oracle用户创建及权限设置

    权限: create session create table unlimited tablespace connect resource dba 例: #sqlplus /nolog SQL> ...

  7. table 操作

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  8. [LeetCode]题解(python):064-Minimum Path Sum

    题目来源 https://leetcode.com/problems/minimum-path-sum/ Given a m x n grid filled with non-negative num ...

  9. python 递归

    学习python,正好用一个例子练习一下递归. 参考文档: http://www.runoob.com/python/python-exercise-example18.html 题目:求s=a+aa ...

  10. eclipse for hello world makefile

    1. 工程文件分析 使用eclipse新建一个Hello World工程,假设工程名称是hello,此时eclipse在工程目录下新建了一个名为hello的文件夹: hello/ .cproject ...