首页 > 其他 > 详细

gzhu 2013 Good Sequence 解题报告

时间:2014-03-18 12:02:26      阅读:478      评论:0      收藏:0      [点我收藏+]

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

bubuko.com,布布扣
 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 
 5 const int maxn = 5000 + 10;
 6 int p[maxn], dp[2*maxn];
 7 
 8 int main()
 9 {
10     int i, j, n;
11     while (scanf("%d", &n) != EOF)
12     {
13         for (i = 1; i <= n; i++)
14          {
15             scanf("%d", &p[i]);
16             dp[i] = 1;
17          }
18         int ans = dp[1];
19         for (i = 2; i <= n; i++)
20         {
21             for (j = 1; j <= i-1; j++)
22             {
23                 if (p[j] <= p[i] && dp[j] + 1 >= dp[i])
24                 {
25                     dp[i] = dp[j] + 1;
26                     ans = max(ans, dp[i]);
27                 }
28             }
29         }
30         printf("%d\n", n-ans);
31     }
32     return 0;
33 }
bubuko.com,布布扣

 


gzhu 2013 Good Sequence 解题报告,布布扣,bubuko.com

gzhu 2013 Good Sequence 解题报告

原文:http://www.cnblogs.com/windysai/p/3606444.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!