hdu 5256 LIS变形
给一个数列,问最少修改多少个元素使数列严格递增。如果不是要求“严格”递增,那就是求最长不降子序列LIS,然后n-LIS就是答案。要严格递增也好办,输入的时候用每个数减去其下标处理一下就行了。
/*
* Author : ben
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <functional>
#include <numeric>
#include <cctype>
using namespace std;
const int MAXN = ;
int a[MAXN];
vector<int> v;
int work() {
int n;
scanf("%d", &n);
v.clear();
vector<int>::iterator it;
for (int i = ; i < n; i++) {
scanf("%d", &a[i]);
a[i] = a[i] - (i + ); //每一个数减去其所在位置的序号
}
v.push_back(a[]);
for (int i = ; i < n; i++) {
if (a[i] >= *(v.end() - )) {
v.push_back(a[i]);
} else {
it = upper_bound(v.begin(), v.end(), a[i]);
*(it) = a[i];
}
}
return n - v.size();
}
int main() {
int T;
scanf("%d", &T);
for (int t = ; t <= T; t++) {
printf("Case #%d:\n%d\n", t, work());
}
return ;
}
hdu 5256 LIS变形的更多相关文章
- hdu 1087(LIS变形)
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- Super Jumping! Jumping! Jumping!(hdu 1087 LIS变形)
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- hdu 5125(LIS变形)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5125 题解: 这个题dp[i][0],dp[i][1]数组分别记录在第i个位置取a[i]和b[i]时 ...
- hdu 2881(LIS变形)
Jack's struggle Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) ...
- 序列变换 HDU - 5256
序列变换 HDU - 5256 题目链接 题目 我们有一个数列A1,A2...An,你现在要求修改数量最少的元素,使得这个数列严格递增.其中无论是修改前还是修改后,每个元素都必须是整数. 请输出最少需 ...
- 九度 1557:和谐答案 (LIS 变形)
题目描述: 在初试即将开始的最后一段日子里,laxtc重点练习了英语阅读的第二部分,他发现了一个有意思的情况.这部分的试题最终的答案总是如下形式的:1.A;2.C;3.D;4.E;5.F.即共有六个空 ...
- UVA 437 巴比伦塔 【DAG上DP/LIS变形】
[链接]:https://cn.vjudge.net/problem/UVA-437 [题意]:给你n个立方体,让你以长宽为底,一个个搭起来(下面的立方体的长和宽必须大于上面的长和宽)求能得到的最长高 ...
- hdu 5256 序列变换 (LIS变形)
序列变换 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- HDU 5489 Removed Interval (LIS变形)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5489 给你n个数,要删去其中连续的L个,问你删去之后的LIS最大是多少? 我们先预处理出以i下标为开头 ...
随机推荐
- Windows下搭建Android开发环境
1.下载eclipse google eclipse,到官网去下载最新版的,推荐java ee版本的,当然你要用android版本或者standard也无妨 2.下载android sdk,安装相关的 ...
- UITextField的总结
1.UITextField的初始化和设置 textField = [[UITextField alloc] initWithFrame:CGRectMake(120.0f, 80.0f, 150.0f ...
- istream, outstream使用及常见错误
使用方法: 使用filebuf打开文件,并拷贝给istream/ostream. 如下面的例子中,实现读取并处理deseq文件夹下所有文件,输出到ostream fw. code: #include& ...
- ACM数据结构相关资料整理【未完成,待补充】
在网上总是查不到很系统的练ACM需要学习的数据结构资料,于是参考看过的东西,自己整理了一份. 能力有限,欢迎大家指正补充. 分类主要参考<算法竞赛入门经典训练指南>(刘汝佳),山东大学数据 ...
- poj2265
斜坐标系,注意找规律.说明在代码里. e- ?(x):-(x))<eps) ][] = { { , }, { -, }, { -, }, { , - }, { , - }, { , } ...
- flex 4 transition
<s:transitions> <s:Transition fromState="default"> <s:Parallel> <mx:R ...
- Ubuntu 14.04怎样升级到Ubuntu 14.10
Ubuntu 14.04怎样升级到Ubuntu 14.10 Ubuntu 14.10 Utopic Unicorn 将在10月23日正式发布,9月25日最终测试版本已经发布,Ubuntu 14 ...
- 1.Cadence16.5的安装教程[原创]
http://jingyan.baidu.com/article/6d704a1319107a28db51cac9.html
- GMT and CST
GMT(Greenwich Mean Time) 代表格林尼治标准时间 而CST却同时可以代表如下 4 个不同的时区: Central Standard Time (USA) UT-6:00 C ...
- [NYIST32]组合数(状压,枚举,暴力)
题目链接:http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=32 求n个数中挑出r个数字的所有情况,最后倒序输出所有情况. 状压枚举所有情况就是了 ...