题目链接:(这个是内网的网址)  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

3
60 54 30
5
44 55 100 72 89

Sample Output

2
1 写下这题是为了纪念我蹩脚的DP!!!
求出最长非递减序列的个数,然后拿n - 个数 就是答案
 #include <iostream>
#include <cstdio>
using namespace std; const int maxn = + ;
int p[maxn], dp[*maxn]; int main()
{
int i, j, n;
while (scanf("%d", &n) != EOF)
{
for (i = ; i <= n; i++)
{
scanf("%d", &p[i]);
dp[i] = ;
}
int ans = dp[];
for (i = ; i <= n; i++)
{
for (j = ; j <= i-; j++)
{
if (p[j] <= p[i] && dp[j] + >= dp[i])
{
dp[i] = dp[j] + ;
ans = max(ans, dp[i]);
}
}
}
printf("%d\n", n-ans);
}
return ;
}
  

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. spring springmvc js websocket 监听

    第一步:web.xml中支持异步.所有的filter及servlet <filter> <filter-name>characterEncoding</filter-na ...

  2. DEDECMS5.5怎样调用{dede:field.content/}做简介之类的单独页面?

    很多时候,如果用dede来做一些企业公司网站,或者一些部门网站的时候.需要某些栏目是一个单页的文章,用于公司简介或者企业文化之类的.那么就要用到栏目功能的栏目内容,也就是dede的content标签. ...

  3. OpenSceneGraph FAQ 【转】

    1.地球背面的一个点,计算它在屏幕上的坐标,能得到吗? 不是被挡住了吗? 答:计算一个空间点的屏幕坐标,使用osgAPEx::GetScreenPosition函数.当空间点处于相机视空间内(不管它是 ...

  4. [Algorithm] Write a Depth First Search Algorithm for Graphs in JavaScript

    Depth first search is a graph search algorithm that starts at one node and uses recursion to travel ...

  5. js json 对象

    JSON 语法规则 JSON 语法是 JavaScript 对象表示法语法的子集. 数据在名称/值对中 数据由逗号分隔 大括号保存对象 中括号保存数组 JSON 名称/值对 JSON 数据的书写格式是 ...

  6. 4.php整合Memcached

    用法: nginx响应请求时,直接请求memcached, 如果没有相应的内容,再回调PHP页面,去查询database,并写入memcached. 分析: memcached是k/v存储, key- ...

  7. hdu 5316 Magician 线段树

    链接:http://acm.hdu.edu.cn/showproblem.php? pid=5316 Magician Time Limit: 18000/9000 MS (Java/Others)  ...

  8. Ipython基础功能

    ipython:交互式的python命令行 直接在终端敲命令即可进入 安装:pip install ipython 使用:在终端敲“ipython” 与python解释器的使用方法一致 TAB键自动补 ...

  9. fedora delete openJDK

    博客分类: linux   由于Fedora系统安装的时候会自带OpenJDK,安装完系统后 java -version 会显示  [root@localhost bin]# java -versio ...

  10. ASP.NET MVC模式——WebPages

    WebPages 示例 123456<html> <body> <h1>Hello Web Pages</h1> <p>The time i ...