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 ...
随机推荐
- Ubuntu 16.04安装字体管理工具
注意:这个字体管理工具只是简化了字体的安装和卸载,并没有快速下载字体去自动安装,所有的字体都是需要自行下载,因为字体本身是有版权的. 安装: sudo apt-get install font-man ...
- Mac os x 10.8 svn server的搭建
Mac自带了svn服务端和客户端,所以我们不用再去下载了. 1 但首先 sudo vi /etc/paths 将xcode里的Contents/developer/usr/bin加入到path ...
- ios 使用 resignFirstResponder 无法hide键盘
- (BOOL)disablesAutomaticKeyboardDismissal { return NO;}
- iOS -- SKPhysicsJointSpring类
SKPhysicsJointSpring类 继承自 NSObject 符合 NSCoding(SKPhysicsJoint)NSObject(NSObject) 框架 /System/Library ...
- CSRF攻击 & XSS攻击
之前有几篇文章写了 SQL注入类问题: http://www.cnblogs.com/charlesblc/p/5987951.html (介绍) http://www.cnblogs.com/cha ...
- php 源码编译
https://cyberpersons.com/2016/08/28/install-nginx-php-php-fpm-mysql-source-run-wordpress-site-ubuntu ...
- MRP routing设置释疑
Jeffer9@gmail.com 工艺是指在不同工作中心执行的作业序列 作业的详细信息 Number of cycles 在该工作中心操作几个循环 Number of ...
- 修改Qweb报表
Table of Contents 将报表的类型改为HTML 打印HTML格式报表 使用html editor 修改报表模板 使用Web builder修改报表 恢复报表格式 将报表的 ...
- openERP server action,最强大的功能,没有之一
Jeffery9@gmail.com 出品 @jeffery-陈帆 原理 ations OE定义了ir.actions.actions,并从中派生了众多的子类 ir.actions.client ir ...
- Codeforces初体验
Codeforces印象 这两天抽时间去codeforces体验了一把. 首先,果然有众多大牛存在.非常多名人一直參加每周一次的比赛.积分2000+,并參与出题. 另外.上面题目非常多.预计至少一千题 ...