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. jquery jstree 插件的使用

    最近一个项目 需要用到jstree 这个jQuery插件,就研究了下,做目录树 菜单还是很强大的,下面对经常会用到几个用法做下说明. 1. 首先页面 引用 jquery.jstree 2. html ...

  2. C# 执行sql语句批量更新

    int x = db.Database.ExecuteSqlCommand(string.Format("update T_Pension SET UnitType = '{0}' WHER ...

  3. Swift 3到5.1新特性整理

    本文转载自:https://hicc.me/whats-new-in-swift-3-to-5-1/,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有. Hipo 2.0 重写从 Swif ...

  4. ajax post 请求报错Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' heade

    jquery ajax跨域请求,webapi webconfig配置 前台代码(放了一部分) function CheckIn(roomno) { $.ajax({ url: 'https://www ...

  5. kernel-内核抢占

    kernel-内核抢占 这里有两个概念,内核抢占与用户态抢占.什么是内核抢占?就是指程序执行系统调用的时候(也就是执行于内核态的时候)被其他内核线程抢占走了. 有2种情况是不会也不应该被抢占的: 内核 ...

  6. Mac 执行 gulp 报错 -bash: gulp: command not found

    在mac系统下安装gulp,之后执行gulp 报如下错误: -bash: gulp: command not found 回溯安装过程发现问题如下 1.执行 npm root: Application ...

  7. 【数据结构】C语言栈的基本操作

    #include<stdio.h> #include<stdlib.h> #include<malloc.h> //定义节点 struct Node { int d ...

  8. 00_Rust安装及Hello World

    Rust 官网: https://www.rust-lang.org 版本:nightly.beta.stable 如何设计语言的讨论:https://github.com/rust-lang/rfc ...

  9. 30.IK分词器配置文件讲解以及自定义词库

    主要知识点: 知道IK默认的配置文件信息 自定义词库     一.ik配置文件     ik配置文件地址:es/plugins/ik/config目录     IKAnalyzer.cfg.xml:用 ...

  10. copy the content of a file muliptle times and save as ordered files:

    input: transient.case outputs: transient_1.case, transient_2.case,...transient_101.case ********** n ...