题目链接:(这个是内网的网址)  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. java并发之hashmap

    在Java开发中经常会使用到hashmap,对于hashmap又了解多少,经常听到的一句话是hashmap是线程不安全的,那为什么是线程不安全的,如何才能保证线程安全,JDK又给我们提供了那些线程安全 ...

  2. 初学ElasticSeacher

    这周,刚接手了同事那边的工作,项目里需要用到ElasticSeacher.但是,之前从未接触过,因此,看了ES的文档,开始慢慢的知道了一些ES的知识. 一.ES简介: Elasticsearch是一个 ...

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

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

  4. iOS --SKView类

    SKView类 继承自 UIView:UIResponder:NSObject 符合 NSCoding(UIView)UIAppearance(UIView)UIAppearanceContainer ...

  5. asyncTask 的execute和executeOnExecutor 方法

    asyncTask.execute Android.os.Build.VERSION_CODES.DONUT, this was changed to a pool of threads allowi ...

  6. 如何模拟alert/confirm/prompt实现阻断程序运行

    场景:在执行js的时候,我们希望运行到某处,进行用户交互,根据交互的内容,运行下面的程序:下面的js程序需要用的和用户交互的内容,所以,和用户交互时,后面的程序必须停止运行 方案: 1. 原生的ale ...

  7. 深入理解vue路由的使用

    vue-router是Vue.js官方的路由插件,它和vue.js是深度集成的,适合用于构建单页面应用.vue的单页面应用是基于路由和组件的,路由用于设定访问路径,并将路径和组件映射起来.传统的页面应 ...

  8. ios 清理缓存(EGO)

    一段清理缓存的代码例如以下: dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,) , ^{ NSSt ...

  9. vue2.0 自定义 饼状图 (Echarts)组件

    1.自定义  图表  组件 Echarts.vue <!-- 自定义 echart 组件 --> <template> <div> <!-- echart表格 ...

  10. js增加收藏

    <html> <span style="white-space:pre"> </span><head> <span style ...