给一个数列,问最少修改多少个元素使数列严格递增。如果不是要求“严格”递增,那就是求最长不降子序列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变形的更多相关文章

  1. hdu 1087(LIS变形)

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  2. Super Jumping! Jumping! Jumping!(hdu 1087 LIS变形)

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  3. hdu 5125(LIS变形)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5125 题解: 这个题dp[i][0],dp[i][1]数组分别记录在第i个位置取a[i]和b[i]时 ...

  4. hdu 2881(LIS变形)

    Jack's struggle Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) ...

  5. 序列变换 HDU - 5256

    序列变换 HDU - 5256 题目链接 题目 我们有一个数列A1,A2...An,你现在要求修改数量最少的元素,使得这个数列严格递增.其中无论是修改前还是修改后,每个元素都必须是整数. 请输出最少需 ...

  6. 九度 1557:和谐答案 (LIS 变形)

    题目描述: 在初试即将开始的最后一段日子里,laxtc重点练习了英语阅读的第二部分,他发现了一个有意思的情况.这部分的试题最终的答案总是如下形式的:1.A;2.C;3.D;4.E;5.F.即共有六个空 ...

  7. UVA 437 巴比伦塔 【DAG上DP/LIS变形】

    [链接]:https://cn.vjudge.net/problem/UVA-437 [题意]:给你n个立方体,让你以长宽为底,一个个搭起来(下面的立方体的长和宽必须大于上面的长和宽)求能得到的最长高 ...

  8. hdu 5256 序列变换 (LIS变形)

    序列变换 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  9. HDU 5489 Removed Interval (LIS变形)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5489 给你n个数,要删去其中连续的L个,问你删去之后的LIS最大是多少? 我们先预处理出以i下标为开头 ...

随机推荐

  1. Java-马士兵设计模式学习笔记-命令模式

    一.概述 命令模式 二.代码 1.Client.java public class Client { public void request(Server server){ server.addCom ...

  2. Swagger PHP使用指南

    先说什么是Swagger, Swagger的使用目的是方便优美的呈现出接口API的各种定义, 生成API文档, 包括参数, 路径之类. 有时后端改了API的参数或者其他设置, 前端直接看这个Swagg ...

  3. ajax 一个 gbk 目标后内容乱码的解决方案

    ajax 一个 gbk 目标后,如果内容出现乱码,说明服务器在送出内容时没有指定 charset,ajax 对于没有指定 charset 的 response 默认以 utf-8 来处理,所有出现乱码 ...

  4. leetcode Database3(Nth Highest Salary<—>Consecutive Numbers<—>Department Highest Salary)

    一.Nth Highest Salary Write a SQL query to get the nth highest salary from the Employee table. +----+ ...

  5. 《OD学HBase》20160820

    一.案例 微博: 微博内容: 关注用户和粉丝用户: 添加或移除关注用户 查看关注用户的微博内容 微博数据存储: 响应时间 秒级 无延迟 (1)mysql分布式 (2)hbase数据库 使用HBase数 ...

  6. ssh传输出现encountered 1 errors during the transfer解决办法

    以下方法简单排序,从简单到复杂: 法一:在SSH Secure File Transfer(上传文件那个),打开“Operation”菜单,打开“File Transfer Mode”子菜单,再选择“ ...

  7. Spring安全框架 Spring Security

    Spring Security 的前身是 Acegi Security ,是 Spring 项目组中用来提供安全认证服务的框架. Spring Security  为基于J2EE企业应用软件提供了全面 ...

  8. github概念和实战

    fork: 通过fork操作,你将拥有了别人创建的repo的ownership,但是url却变成了/youraccount/repo,这时你将可以做git push操作 clone: 该命令是直接将r ...

  9. LA 3971 (二分) Assemble

    题意: 你有b块钱想要组装一台电脑.给出n个配件的种类,品质和价格,要求每个种类的配件各买一个总价格不超过b且“品质最差配件”的品质因子应尽量大. 这种情况下STL的map的确很好用,学习学习 这种最 ...

  10. hdu4638 group 树状数组

    连接:http://acm.hdu.edu.cn/showproblem.php?pid=4638 题意:就给给你n个数(大小在1-n里),然后给你连续的可以构成一个块,再给你N个询问,每个询问一个l ...