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. __declspec(dllexport)

    __declspec(dllexport) (2010-06-17 10:04:28) 转载▼ 标签: __declspec dllexport 导出 it 分类: C 先看代码:以下是在dev-c+ ...

  2. ubuntu.16.04 安装.net core记录

    jack@ubuntu:~$ sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotne ...

  3. 如何从源码启动和编译IoTSharp

    IoTSharp 项目是一个开源物联网平台,数据库使用PostgreSQL , 后端使用 Asp.Net Core 2.2 ,前端使用  vue-element-admin , 下面我们介绍如何启动项 ...

  4. P1352 没有上司的舞会——树形DP入门

    P1352 没有上司的舞会 题目描述 某大学有N个职员,编号为1~N.他们之间有从属关系,也就是说他们的关系就像一棵以校长为根的树,父结点就是子结点的直接上司.现在有个周年庆宴会,宴会每邀请来一个职员 ...

  5. Python 字符串和数字

    Python 变量类型 变量存储在内存中的值.这就意味着在创建变量时会在内存中开辟一个空间. 基于变量的数据类型,解释器会分配指定内存,并决定什么数据可以被存储在内存中. 因此,变量可以指定不同的数据 ...

  6. wx微信小程序

    俩三行时: ==========

  7. Codeforces 432D Prefixes and Suffixes (KMP、后缀数组)

    题目链接: https://codeforces.com/contest/432/problem/D 题解: 做法一: KMP 显然next树上\(n\)的所有祖先都是答案,出现次数为next树子树大 ...

  8. Beetl学习总结(4)——Web集成

    4.1. Web提供的全局变量 Web集成模块向模板提供web标准的变量,做如下说明 request 中的所有attribute.在模板中可以直接通过attribute name 来引用,如在cont ...

  9. 几个有用的shell命令

    1.!$ 是一个特殊的环境变量,它代表了上一个命令的最后一个字符串.如:你可能会这样: $mkdir mydir$mv mydir yourdir$cd yourdir 可以改成: $mkdir my ...

  10. 2017 Multi-University Training Contest - Team 4 Classic Quotation

    Classic Quotation Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Othe ...