最长上升子序列的变形(N*log(N))hdu5256
序列变换
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 820 Accepted Submission(s): 336
请输出最少需要修改多少个元素。
每一组数据:
第一行输入一个N(1≤N≤105),表示数列的长度
第二行输入N个数A1,A2,...,An。
每一个数列中的元素都是正整数而且不超过106。
Case #i:
然后输出最少需要修改多少个元素。
#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的更多相关文章
- DP专辑之最长公共子序列及其变形
vijos1111(裸的最长公共子序列) 链接:www.vijos.org/p/1111 题解:好久没有写最长公共子序列了,这题就当是复习了.求出最长公共子序列,然后用两个单词的总长度减去最长公共子序 ...
- hdu5282 最长公共子序列的变形
pid=5282">http://acm.hdu.edu.cn/showproblem.php?pid=5282 Problem Description Xuejiejie loves ...
- Bridging signals---hdu1950(最长上升子序列复杂度n*log(n) )
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1950 一直只知道有除n*n的算法之外的求LIS,但是没学过,也没见过,今天终于学了一下,dp[i]表 ...
- ZOJ3519-Beautiful People:最长上升子序列的变形
Beautiful People Special JudgeTime Limit: 10000/5000MS (Java/Others)Memory Limit: 128000/64000KB (Ja ...
- 最长上升子序列(LIS)的n*log(n)求法
方法: 对于某个序列,设一个数组,将序列第一个数放入,然后再一个一个判断序列下一位,如果大于当前数组的末尾元素,则加入数组,否则利用二分法找到第一个大于等于当前数的元素并替换,最后这个数组的长度len ...
- HDU 1080 Human Gene Functions - 最长公共子序列(变形)
传送门 题目大意: 将两个字符串对齐(只包含ACGT,可以用'-'占位),按照对齐分数表(参见题目)来计算最后的分数之和,输出最大的和. 例如:AGTGATG 和 GTTAG ,对齐后就是(为了表达对 ...
- hdu1503 最长公共子序列变形
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1503 题意:给出两个字符串 要求输出包含两个字符串的所有字母的最短序列.注意输出的顺序不能 ...
- ACM: 强化训练-Beautiful People-最长递增子序列变形-DP
199. Beautiful People time limit per test: 0.25 sec. memory limit per test: 65536 KB input: standard ...
- hdu 1080 dp(最长公共子序列变形)
题意: 输入俩个字符串,怎样变换使其所有字符对和最大.(字符只有'A','C','G','T','-') 其中每对字符对应的值如下: 怎样配使和最大呢. 比如: A G T G A T G - G ...
随机推荐
- Checklist For Choosing The Right Database Engine
http://sqlite.org/whentouse.html Appropriate Uses For SQLite SQLite is not directly comparable to cl ...
- cascading rollback 级联回滚
Computer Science An Overview _J. Glenn Brookshear _11th Edition To emphasize the delicate nature of ...
- __LINE__ check_arr_empty($arr)
<?php $arr = array('','',''); foreach($arr as $w) { // w(empty($w)); } w(empty($arr)); w(check_ar ...
- StartSSL免费证书申请笔记
第一步:申请startssl账号 填写相应信息后,你所填写的邮箱会收到邮件 里面有一个用来验证的验证码 输入得到的.... 注册成功后会安装数字证书(注意:注册过程中没有叫输入账号密码,这也是通过证认 ...
- Qt系统托盘
Qt的系统托盘的使用,可比mfc中好多了!他封装了一个专门的QSystemTrayIcon类,建立系统托盘图标.其实在Qt提供的示例程序已经很不错了,$QTDIR\examples\desktop\s ...
- IE中的fireEvent和webkit中的dispatchEvent
拿浏览器的click事件来说: 在IE浏览器中如果一个element没有注册click事件,那么直接调用的话会出现异常!当然如果你注册了没有什么可说的. 那么如果使用fireEvent来处理,clic ...
- [LeetCode]题解(python):056-Merge Intervals
题目来源 https://leetcode.com/problems/merge-intervals/ Given a collection of intervals, merge all overl ...
- [LeetCode]题解(python):037-Sudoku Solver
题目来源 https://leetcode.com/problems/sudoku-solver/ Write a program to solve a Sudoku puzzle by fillin ...
- 利用HTML和JS制作隔行换背景颜色的表格
1.源代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww ...
- opengl 3.3 tutorial
http://www.mbsoftworks.sk/index.php?page=tutorials&series=1