POJ 1837 简单 DP 二逼 DP = =
来源:互联网 发布:网络平台销售管理 编辑:程序博客网 时间:2024/05/21 14:45
这个题,让我看到就想到最长上升子序列,1000的大小,n^2 就可以
但是注意到,最高的两个士兵可以是相同身高的,所以,再求出左右两个最长上升子序列之后,最后得出结果的时候要注意这一点。
这个地方 WA 了好多次, 这个题目的通过率这么低 应该就是这个点。
#include <stdio.h>#include <algorithm>#include <string.h>#include <iostream>using namespace std;#define MAX 20000int n;int dpl[MAX];int dpr[MAX];double h[MAX];int main(){freopen("acm.in","r",stdin);while(scanf("%d",&n)!=EOF){for(int i=1;i<=n;i++)scanf("%lf",&h[i]);memset(dpl,0,sizeof(dpl));memset(dpr,0,sizeof(dpr));for(int i=1;i<=n;i++){dpl[i]=1;for(int j=1;j<i;j++){if(h[i]>h[j])dpl[i]=max(dpl[i],dpl[j]+1);}}for(int i=n;i>=1;i--){dpr[i]=1;for(int j=n;j>i;j--){if(h[i]>h[j])dpr[i]=max(dpr[i],dpr[j]+1);}}int maxl=0;for(int i=1;i<=n;i++){maxl=max(maxl,dpl[i]+dpr[i]-1);for(int j=i+1;j<=n;j++)if(h[i]==h[j])maxl=max(maxl,dpl[i]+dpr[j]);}printf("%d\n",n-maxl);}return 0;}
0 0
- POJ 1837 简单 DP 二逼 DP = =
- POJ 2181简单DP
- POJ-2004 简单DP..
- poj 2385 简单dp
- poj 3486 简单dp
- poj 2353 简单dp
- poj-2355-简单dp
- poj-2479 简单DP
- poj 3267 简单dp
- poj 3132简单dp
- poj 3280 简单dp
- poj 2948 简单dp
- POJ 3176 简单DP
- POJ 3176 简单DP
- poj 3616(简单dp)
- poj 3920(简单dp)
- poj 2355(简单dp)
- POJ 2479 (简单dp)
- SPOJ 345 Mixtures(JAVA版)
- 【cocos2d-x官方文档】瓦片地图 Tiled Map
- Paros 抓取iPhone信息。
- 关于js区分刷新和关闭的
- 并非哲学
- POJ 1837 简单 DP 二逼 DP = =
- MediaPlayer IllegalStateException
- 学习
- 汇编学习计划
- 黑马程序员_多线程1
- Cocos2d-x 的“HelloLua” 深入分析 (一)
- 人生三句话
- 如何判断PHP 是线程安全还是非线程安全的
- 写个2D刚体模拟器,麻雀虽小五脏俱全