POJ-1836 Alignment---LIS】的更多相关文章

题意:n个士兵站成一排,求去掉最少的人数,使剩下的这排士兵的身高形成“峰形”分布,即求前面部分的LIS加上后面部分的LDS的最大值. 做法:分别求出LIS和LDS,枚举中点,求LIS+LDS的最大值.. 注意一点,有可能最中间的值重复,也有可能不重复,所以要考虑这两种情况:(假设中点为K) 1)不重复的情况,求LIS(K) + LDS(K+1)的最大值 2)重复的情况,这时K既包含在LIS当中,也包含在LDS中,计算了两次,最终结果要减掉1 复杂度:O(n^2) 代码: #include <io…
大致题意:给出一队士兵的身高,一开始不是按身高排序的.要求最少的人出列,使原序列的士兵的身高先递增后递减. 求递增和递减不难想到递增子序列,要求最少的人出列,也就是原队列的人要最多. 1 2 3 4 5 4 3 2 1 这个序列从左至右看前半部分是递增,从右至左看前半部分也是递增.所以我们先把从左只右和从右至左的LIS分别求出来. 如果结果是这样的: A[i]={1.86 1.86 1.30621 2 1.4 1 1.97 2.2} //原队列 a[i]={1 1 1 2 2 1 3 4} b[…
Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 11450 Accepted: 3647 Description In the army, a platoon is composed by n soldiers. During the morning inspection, the soldiers are aligned in a straight line in front of the captain…
题目:http://poj.org/problem?id=1836 题意:最长上升子序列问题, 站队,求踢出最少的人数后,使得队列里的人都能看到 左边的无穷远处 或者 右边的无穷远处. 代码O(n^2): #include<iostream> #include<cstring> using namespace std; int main() { ],d2[],mx; ]; cin>>n; ; i<=n; i++) cin>>a[i]; d1[]=; ;…
题目: http://poj.org/problem?id=1836 没读懂题,以为身高不能有相同的,没想到排中间的两个身高是可以相同的.. #include <stdio.h> #include <string.h> #include <iostream> ], dpl[]; int main() { int n; ]; while(scanf("%d", &n) != EOF) { ; i <= n; i++) { std::cin…
题目链接:http://poj.org/problem?id=1836 思路分析:假设数组为A[0, 1, …, n],求在数组中最少去掉几个数字,构成的新数组B[0, 1, …, m]满足条件B[0] < B[1] <….<B[i] 且 B[i+1] > … > B[m]; 该问题实质为求A[0, …, k]的最长递增子序列和A[j, …, n]中的最长递减子序列(0 <= k <= n, 0 <= j <= n, k < j);所以求出A[0…
https://vjudge.net/problem/POJ-1836 题意 求最少删除的数,使序列中任意一个位置的数的某一边都是递减的. 分析 任意一个位置的数的某一边都是递减的,就是说对于数h[i],有h[1] ~ h[i]严格单增,或h[i] ~ h[n]严格单减.一开始读错题意,以为使总体递增或递减,使劲wa...求两个方向的LIS,用n^2解法即可. #include<iostream> #include<cmath> #include<cstring> #i…
Alignment Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 10804   Accepted: 3464 Description In the army, a platoon is composed by n soldiers. During the morning inspection, the soldiers are aligned in a straight line in front of the cap…
Alignment Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 14486   Accepted: 4695 Description In the army, a platoon is composed by n soldiers. During the morning inspection, the soldiers are aligned in a straight line in front of the cap…
题目链接http://poj.org/problem?id=1836 Alignment Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 17331   Accepted: 5694 Description In the army, a platoon is composed by n soldiers. During the morning inspection, the soldiers are aligned in…