http://poj.org/problem?id=1836

求两遍最长上升子序列,顺序求一遍,逆序求一遍。

 #include <stdio.h>
#include <string.h>
const int N=;
int dp1[N],dp2[N];
double a[N];
int main()
{
int n;
scanf("%d",&n);
for (int i = ; i <= n; i++)
{
scanf("%lf",&a[i]);
}
dp1[] = ;
for (int i = ; i <= n; i++)
{
int temp = ;
for (int j = ; j < i; j++)
{
if (a[i] > a[j])
{
if (temp < dp1[j])
temp = dp1[j];
}
}
dp1[i] = temp+;
}
dp2[n] = ;
for (int i = n-; i > ; i--)
{
int temp = ;
for (int j = n; j > i; j--)
{
if (a[i] > a[j])
{
if (temp < dp2[j])
temp = dp2[j];
}
}
dp2[i] = temp+;
}
int Max = ;
for (int i = ; i <= n; i++)
{
for (int j = i+; j <= n; j++)
{
if (Max < dp1[i]+dp2[j])
Max = dp1[i]+dp2[j];
}
}
printf("%d\n",n-Max);
return ;
}

Alignment(dp)的更多相关文章

  1. poj 1836 Alignment(dp)

    题目:http://poj.org/problem?id=1836 题意:最长上升子序列问题, 站队,求踢出最少的人数后,使得队列里的人都能看到 左边的无穷远处 或者 右边的无穷远处. 代码O(n^2 ...

  2. POJ 1836 Alignment (双向DP)

    Alignment Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 10804   Accepted: 3464 Descri ...

  3. POJ 1836 Alignment(DP max(最长上升子序列 + 最长下降子序列))

    Alignment Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 14486   Accepted: 4695 Descri ...

  4. POJ 1836 Alignment 水DP

    题目: http://poj.org/problem?id=1836 没读懂题,以为身高不能有相同的,没想到排中间的两个身高是可以相同的.. #include <stdio.h> #inc ...

  5. poj 1836 Alignment(线性dp)

    题目链接:http://poj.org/problem?id=1836 思路分析:假设数组为A[0, 1, …, n],求在数组中最少去掉几个数字,构成的新数组B[0, 1, …, m]满足条件B[0 ...

  6. POJ 1836 Alignment

    Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 11450 Accepted: 3647 Descriptio ...

  7. poj1080--Human Gene Functions(dp:LCS变形)

    Human Gene Functions Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17206   Accepted:  ...

  8. HDU1080(DP)

    我用的dp是n^3的, dp[i][j] 表示在s串的i个前和t串的j个前,s[i],t[j]为最末端的两个串得到的最大值. 状态转移方程为: 之前将s和t串最尾端添加'-' ;i<=n;i++ ...

  9. POJ 1080:Human Gene Functions LCS经典DP

    Human Gene Functions Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18007   Accepted:  ...

随机推荐

  1. Python_多线程1(创建线程,简单线程同步)

    threading 模块除了包含 _thread 模块中的所有方法外,还提供的其他方法: threading.currentThread(): 返回当前的线程变量. threading.enumera ...

  2. 吐得了,vue的多选组合框回显必须是字符串集合

    下面这个typeIdList,如果给他赋值,就能回显到页面,但是必须是字符串的集合,如果是数值类型的id,不好意思,请转成字符串

  3. Oracle 函数总结

    <1>=========================返回 String,其中包含有与指定的字符代码相关的字符======================== 函      数:< ...

  4. cad二次开发中各种头的定义

    Database db=HostApplicationServices.WrokingDatabase; Editor ed=Autodesk.AutoCAD.ApplicationService.A ...

  5. php第十三节课

    查询 <?php class DBDA{ public $host = "localhost"; //数据库地址 public $uid = "root" ...

  6. Opencv学习之路——自己编写的HOG算法

    #include<opencv2\core\core.hpp> #include<opencv2\highgui\highgui.hpp> #include<opencv ...

  7. 39.date hitogram基础知识

    主要知识点: date hitogram之统计每月电视销量     上一节讲到histogram,他是以数值进行分组.本节讲到以日期进行bucket分组操作,也就是说把连续的日期变成离散的日期区间,然 ...

  8. 基于supervisor秒级Laravel定时任务

    背景介绍 公司需要实现X分钟内每隔Y秒轮训某个接口,Linux自带的crontab貌似只精确到分钟,虽然可以到精确到秒,但是并不满足需求. 选型 公司项目都是 基于 Laravel 框架,所以这个没得 ...

  9. Vue ui 大法哪家强?

    Element iView Vuex Mint UI Vant cube-ui,对比六大 vue ui 组件库,选中最适合的那个. Element(pc) 介绍 & 版本 饿了么前端团队开发的 ...

  10. 1. Python中的基本数据类型、运算、变量

    本文利用的是Python 3.x版本,建议学习3.x版本 Python中的基本数据类型.运算.变量 1. 基本数据类型 1.1 整数 py可以处理任意大小的整数,例如123,1234567891324 ...