题目链接:(这个是内网的网址)  http://172.22.27.1/problem?pid=1013

                Good Sequence

Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 128000/64000 KB (Java/Others)

Problem Description

A sequence contains n integers.

A sequence p1, p2, p3...pn is a good sequence if it satisfies pi ≤ pi+1. i∈[1, n)<n)<n)<n)< p="">

KIDx likes good sequence very much. So he has made a random generator in order to generate lots of good sequences.

But unfortunately, there is something wrong with his generator so that it always generates bad sequences.

Now, KIDx has to transform every bad sequence to a good one. He can change any integer  in the sequence.

Your task is to find out the minimum number of integers KIDx has to change to get a good sequence.

Input

Each case contains a positive integer n (n ≤ 5000) in the first line and a sequence which contains n integers pi (0 ≤ p< 108) in the second line.

Output

For each test case, output the answer in a single line.

Sample Input

  1. 3
  2. 60 54 30
  3. 5
  4. 44 55 100 72 89

Sample Output

  1. 2
  2. 1
  3.  
  4. 写下这题是为了纪念我蹩脚的DP!!!
    求出最长非递减序列的个数,然后拿n - 个数 就是答案
  1. #include <iostream>
  2. #include <cstdio>
  3. using namespace std;
  4.  
  5. const int maxn = + ;
  6. int p[maxn], dp[*maxn];
  7.  
  8. int main()
  9. {
  10. int i, j, n;
  11. while (scanf("%d", &n) != EOF)
  12. {
  13. for (i = ; i <= n; i++)
  14. {
  15. scanf("%d", &p[i]);
  16. dp[i] = ;
  17. }
  18. int ans = dp[];
  19. for (i = ; i <= n; i++)
  20. {
  21. for (j = ; j <= i-; j++)
  22. {
  23. if (p[j] <= p[i] && dp[j] + >= dp[i])
  24. {
  25. dp[i] = dp[j] + ;
  26. ans = max(ans, dp[i]);
  27. }
  28. }
  29. }
  30. printf("%d\n", n-ans);
  31. }
  32. return ;
  33. }

gzhu 2013 Good Sequence 解题报告的更多相关文章

  1. USACO Section2.1 Sorting a Three-Valued Sequence 解题报告

    sort3解题报告 —— icedream61 博客园(转载请注明出处)---------------------------------------------------------------- ...

  2. timus 1175. Strange Sequence 解题报告

    1.题目描述: 1175. Strange Sequence Time limit: 1.0 secondMemory limit: 2 MB You have been asked to disco ...

  3. Ducci Sequence解题报告

    A Ducci sequence is a sequence of n-tuples of integers. Given an n-tuple of integers (a1, a2, ... ,  ...

  4. 【LeetCode】842. Split Array into Fibonacci Sequence 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  5. 【LeetCode】60. Permutation Sequence 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  6. poj 2013 Symmetric Order 解题报告

    题目链接:http://poj.org/problem?id=2013 设长度非递减的字串序列为s[1]...s[n].设计递归子程序print(n),其中n为字串序号,每分析1个字串,n=n-1. ...

  7. LeetCode: Permutation Sequence 解题报告

    Permutation Sequence https://oj.leetcode.com/problems/permutation-sequence/ The set [1,2,3,…,n] cont ...

  8. USACO Section 2.1 Sorting a Three-Valued Sequence 解题报告

    题目 题目描述 给N个整数,每个整数只能是1,2,或3.现在需要对这个整数序列进行从小到大排序,问最少需要进行几次交换.N(1 <= N <= 1000) 样例输入 9 2 2 1 3 3 ...

  9. LeetCode: Longest Consecutive Sequence 解题报告

    Longest Consecutive Sequence Given an unsorted array of integers, find the length of the longest con ...

随机推荐

  1. ajax跨域-springboot

    package com.xxxx.xx.service.configuration; import org.springframework.context.annotation.Bean; impor ...

  2. HDU3625 Examining the Rooms

    @(HDU)[Stirling數] Problem Description A murder happened in the hotel. As the best detective in the t ...

  3. Mac item2 配色,大小写敏感及常用快捷键

    http://blog.csdn.net/lainegates/article/details/38313559 目录(?)[-] 配色 大小写敏感 快捷揵   item2是mac下非常好用的一款终端 ...

  4. Java Static Import的用法

    在头部使用的imoirt static ***方式叫做静态引入,在Java SE 1.5.0(JDK 5)引入的特性. 官方文档的介绍: 为了访问静态成员,有必要限定它们来自的类的引用.例如,必须这样 ...

  5. Android --修改arr文件

    1. 改为zip文件 2. 修改 3. 改后缀

  6. 智能手机+DIY红外=万能遥控器

    目前好像只有:三星S4.,努比亚大牛,华为荣耀3等几款新机才有红外遥控功能,那我们使用的手机没有这个功能怎么办?不要急我有办法呵呵,本次DIY材料好找又简单,大家都可以亲自试一试! DIY材料:红外二 ...

  7. python 列表结构更新的奇妙问题

    使用python + plt 画图遇到了一个奇怪的问题 应该出来的是这样: 结果做出来以后是这样: 为什么画到一起了...... 这个锅python列表背 a=[1,2]b=a  这样  改变b ,a ...

  8. JS推断浏览器类型与版本号

    在JS中推断浏览器的类型,预计是每一个编辑过页面的开发者都遇到过的问题.在众多的浏览器产品中.IE.Firefox.Opera.Safari........众多品牌却标准不一,因此时常须要依据不同的浏 ...

  9. 向odoo贡献中文翻译

    建议通过 osc-git向odoo贡献中文翻译     osc-git 是指'开源中国'的git平台. 网址是 http://git.oschina.net/     注册osc-git 账号省略. ...

  10. 线程安全使用(四) [.NET] 简单接入微信公众号开发:实现自动回复 [C#]C#中字符串的操作 自行实现比dotcore/dotnet更方便更高性能的对象二进制序列化 自已动手做高性能消息队列 自行实现高性能MVC WebAPI 面试题随笔 字符串反转

    线程安全使用(四)   这是时隔多年第四篇,主要是因为身在东软受内网限制,好多文章就只好发到东软内部网站,懒的发到外面,现在一点点把在东软写的文章给转移出来. 这里主要讲解下CancellationT ...