gzhu 2013 Good Sequence 解题报告
题目链接:(这个是内网的网址) http://172.22.27.1/problem?pid=1013
Good Sequence
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 ≤ pi < 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 解题报告的更多相关文章
- USACO Section2.1 Sorting a Three-Valued Sequence 解题报告
sort3解题报告 —— icedream61 博客园(转载请注明出处)---------------------------------------------------------------- ...
- timus 1175. Strange Sequence 解题报告
1.题目描述: 1175. Strange Sequence Time limit: 1.0 secondMemory limit: 2 MB You have been asked to disco ...
- Ducci Sequence解题报告
A Ducci sequence is a sequence of n-tuples of integers. Given an n-tuple of integers (a1, a2, ... , ...
- 【LeetCode】842. Split Array into Fibonacci Sequence 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【LeetCode】60. Permutation Sequence 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- poj 2013 Symmetric Order 解题报告
题目链接:http://poj.org/problem?id=2013 设长度非递减的字串序列为s[1]...s[n].设计递归子程序print(n),其中n为字串序号,每分析1个字串,n=n-1. ...
- LeetCode: Permutation Sequence 解题报告
Permutation Sequence https://oj.leetcode.com/problems/permutation-sequence/ The set [1,2,3,…,n] cont ...
- USACO Section 2.1 Sorting a Three-Valued Sequence 解题报告
题目 题目描述 给N个整数,每个整数只能是1,2,或3.现在需要对这个整数序列进行从小到大排序,问最少需要进行几次交换.N(1 <= N <= 1000) 样例输入 9 2 2 1 3 3 ...
- LeetCode: Longest Consecutive Sequence 解题报告
Longest Consecutive Sequence Given an unsorted array of integers, find the length of the longest con ...
随机推荐
- 笔记-迎难而上之Java基础进阶6
import java.io.*; public class InputStreamDemo{ public static void main(String[] args) throws IOExce ...
- SQLServer 跟踪 扩展事件(Extended Events) 专家
http://blog.csdn.net/kk185800961/article/details/49725903
- 详解RocketMQ中的consumer
上述就是MQ中有关Consumer的类图,下面来介绍一下每个类 1.MQAdmin:底层类,上篇博客已经提过,就不再此重提 2.MQConsumer:Consumer公共的接口,常用的方法如下 如果消 ...
- [Django] 查看orm自己主动运行的原始查询sql
django的文档看了非常多.也用了不少,有的时候感觉性能非常不好,知道非常多地方是惰性查询.可是对于复杂的逻辑.仅仅是表面上发现执行非常慢,机器资源消耗非常多.却不知道orm究竟是什么来转化成sql ...
- 百科知识 .e,.ec文件如何打开
1 .e是易语言源文件,你可以从以下网址下载e语言编程环境: http://www.xiazaiba.com/html/409.html 2 安装之后会自动关联.e文件. 3 打开一个e语言文 ...
- JD笔试试题(凭记忆写的+人生感悟 try finally )
京东笔试:技术篇(一套卷.包含測试.算法,研发) 一:填空题(4分 * 15) 15 个 涉及的面很广的选择题,可是比較側重基础.包含数据结构的.c++类的,操作系统的,计算机网络的. 二:编程题(2 ...
- jquery中text(),html(),val()在取值上的区别
1.html():读取和修改一个元素的HTML内容: 2.text():读取和修改一个元素的文本内容: 3.val():读取和修改一个表单元素的value字段值.
- React学习之常用概念
看见一篇不错的文章转载,文章源地址:https://blog.csdn.net/zwp438123895/article/details/69374940 一. State和 Props state ...
- 为Redmine的项目加上起止时间
没有时间约束的项目不是好项目. 要给项目配置起止时间,须要用到自己定义属性. 我们须要管理员身份登录.才干够定义自己定义属性. 自己定义属性 看图吧,先是点击页面导航条(最上面那排菜单,有主页.我的工 ...
- oracle insert/update
insert into table (,,) values (,,) where update table set (,)=(select , from ) where