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. 从JavaScript的单线程执行说起

    先看一段代码: 1 2 3 4 5 setTimeout(function(){     alert("a"); }, 0); while(1); alert("b&qu ...

  2. Python元类(metaclass)以及元类实现单例模式

    这里将一篇写的非常好的文章基本照搬过来吧,这是一篇在Stack overflow上很热的帖子,我看http://blog.jobbole.com/21351/这篇博客对其进行了翻译. 一.理解类也是对 ...

  3. Lazarus Reading XML- with TXMLDocument and TXPathVariable

    也就是使用XPath的方式,具体语法规则查看http://www.w3school.com.cn/xpath/xpath_syntax.asp,说明得相当详细.这里列举例子是说明在Lazarus/FP ...

  4. CSS (层叠样式表)

    层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言.CSS不仅可以静态 ...

  5. 让Android的WebView支持html里面的文件上传

    默认情况下,Android的webview是不支持<input type=file>的,点击没有任何反应,如果希望点击上传,弹出选择文件.图片的窗口,那就需要自定义一个WebChromeC ...

  6. Python3爬取前程无忧数据分析工作并存储到MySQL

    1.导入包import requests #取数from lxml import etree #用xpath解析import pymysql #连接数据库import chardet #自动获取编码2 ...

  7. 最新 Xilinx vivado IP许可申请

    xilinx的fpga使用vivado开发,zynq系列fpga的SOC开发成为主流,加快fpga开发,也进一步提高了fpga开发的灵活性. xilinx提供很多ip核供开发者直接使用,开发快捷方便, ...

  8. Centos7下mysql的主从配置

    最近,有朋友业务并发量比较大,让我帮他配置个主从,来缓解数据库的压力.下面就是我配置的,有需要的朋友可以借鉴下. 首先,我得到2台服务器: 172.18.2.142(主) 172.18.2.141(从 ...

  9. POJ-1655 Balancing Act(树的重心)

    Consider a tree T with N (1 <= N <= 20,000) nodes numbered 1...N. Deleting any node from the t ...

  10. Codeforces 939D - Love Rescue

    传送门:http://codeforces.com/contest/939/problem/D 本题是一个数据结构问题——并查集(Disjoint Set). 给出两个长度相同,且仅由小写字母组成的字 ...