POJ 1836 Alignment (动态规划LIS)
来源:互联网 发布:现代诗歌 知乎 编辑:程序博客网 时间:2024/05/19 04:27
poj 1836
参考博客:http://cavenkaka.iteye.com/blog/1542421 感谢!!
dp1 【 i 】表示前i个人中以第i个人为末尾的最长递增序列,dp2 【i 】表示后n - i + 1个人中以第i个人为起始的最长递减序列。
最后dp1【i】 + dp2【j】(i < j )中最大的即为能留下的最大的人数ans。
而n - ans即为赶走的最少的人数。
关于LIS参考了:http://blog.csdn.net/joylnwang/article/details/6766317 感谢!!!
#include <iostream>#include<algorithm>#include <cstdio>#include <cstring>using namespace std;int main() {//freopen("input.txt", "r", stdin);int n;scanf("%d", &n);double height[1010];int i;for(i = 1; i <= n; i++) {scanf("%lf", &height[i]);}int dp1[1010], dp2[1010];memset(dp1, 0, sizeof(dp1));memset(dp2, 0, sizeof(dp2));dp1[1] = 1;int j;for(i = 2; i <= n; i++) {dp1[i] = 1;for(j = i - 1; j >= 1; j--) {if(height[j] < height[i] && dp1[i] < dp1[j] + 1) { //利用LIS求dp1dp1[i] = dp1[j] + 1;}}}dp2[n] = 1;for(i = n - 1; i >= 1; i--) {dp2[i] = 1;for(j = i + 1; j <= n; j++) {if(height[j] < height[i] && dp2[i] < dp2[j] + 1) {dp2[i] = dp2[j] + 1;}}}int ans = dp1[n] > dp2[1] ? dp1[n] : dp2[1];for(i = 1; i <= n; i++) {for(j = i + 1; j <= n; j++) {if(dp1[i] + dp2[j] > ans) {ans = dp1[i] + dp2[j];}}}printf("%d\n", n - ans); return 0;}
0 0
- POJ 1836 Alignment (动态规划LIS)
- POJ 1836 Alignment(LIS)
- POJ 1836-ALignment 动态规划
- poj-1836-Alignment-动态规划
- POJ 1836 Alignment( LIS )
- POJ 1836 Alignment (LIS)
- poj 1836 Alignment (LIS变形)
- poj 1836 Alignment(dp,LIS)
- POJ 1836-Alignment(DP/LIS变形)
- POJ 1836 Alignment(DP | LIS)
- POJ 1836 Alignment(LIS变形)
- POJ 1836-Alignment(LIS-士兵列队)
- POJ 1836 Alignment DP(LIS)
- POJ 1836--Alignment(LIS,LCS)
- poj 1836 Alignment (DP LIS)
- POJ 1836 Alignment(DP LIS)
- [POJ 1836]Alignment[DP][LIS]
- Poj 1836 Alignment (双重LIS)
- 镜像反转二进制表达式,并输出十进制值
- android的编译和运行过程深入分析
- Cache缓存
- HTML5/CSS3学习笔记
- 对称、非对称加密技术初探
- POJ 1836 Alignment (动态规划LIS)
- 各种有关时间的插件
- android虚拟机详解(5%原创)
- 英尺转换成米
- 程序的链接、装载和库——《程序员的自我修养》笔记
- Unity之android推送
- MyBatis 实践 -配置
- 【极简版GH60】【GH60剖析】【二】原理图的分析
- 去掉dedecms友情链接中的LI标签