Alignment(dp)
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)的更多相关文章
- poj 1836 Alignment(dp)
题目:http://poj.org/problem?id=1836 题意:最长上升子序列问题, 站队,求踢出最少的人数后,使得队列里的人都能看到 左边的无穷远处 或者 右边的无穷远处. 代码O(n^2 ...
- POJ 1836 Alignment (双向DP)
Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 10804 Accepted: 3464 Descri ...
- POJ 1836 Alignment(DP max(最长上升子序列 + 最长下降子序列))
Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 14486 Accepted: 4695 Descri ...
- POJ 1836 Alignment 水DP
题目: http://poj.org/problem?id=1836 没读懂题,以为身高不能有相同的,没想到排中间的两个身高是可以相同的.. #include <stdio.h> #inc ...
- poj 1836 Alignment(线性dp)
题目链接:http://poj.org/problem?id=1836 思路分析:假设数组为A[0, 1, …, n],求在数组中最少去掉几个数字,构成的新数组B[0, 1, …, m]满足条件B[0 ...
- POJ 1836 Alignment
Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 11450 Accepted: 3647 Descriptio ...
- poj1080--Human Gene Functions(dp:LCS变形)
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17206 Accepted: ...
- HDU1080(DP)
我用的dp是n^3的, dp[i][j] 表示在s串的i个前和t串的j个前,s[i],t[j]为最末端的两个串得到的最大值. 状态转移方程为: 之前将s和t串最尾端添加'-' ;i<=n;i++ ...
- POJ 1080:Human Gene Functions LCS经典DP
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18007 Accepted: ...
随机推荐
- RadioButtonList的兩種實現方式
一種是修改ItemTemplate,即ListBoxItem裏面的内容 <ListBox ItemsSource="{Binding}"> <ListBox.It ...
- JavaScript面试题链接汇总
最新JavaScript笔试题(含答案) - 爱思资源网 前端工程师面试问题列表 - 爱思资源网 腾讯最新前端面试题记录分享 - 爱思资源网 优酷前端JS部分面试题 - 爱思资源网 百度校园招聘web ...
- python_时间日期
time.time()用于获取当前时间戳 从返回浮点数的时间辍方式向时间元组转换,只要将浮点数传递给如localtime之类的函数. localtime = time.localtime(time.t ...
- plsql developer连接oracle数据库
1.下载安装PLSQL Developer12 访问PLSQL Developer官网https://www.allroundautomations.com/bodyplsqldevreg.html, ...
- 调用CAD内的颜色选择对话框
colordialog类 int color; acedSetColorDialog(color,TRUE,0); 第一个函数返回的是颜色的RGB值
- PHP 数据库连接 (Mysql Mysqli PDO)
1.PHP与Mysql扩展(本扩展自 PHP 5.5.0 起已废弃,并在将来会被移除),PHP原生的方式去连接数据库,是面向过程的 <?php $mysql_conf = array( 'hos ...
- 模板中tempname与class区别
前言 在分析traits编程之前, 我们需要对模板参数类型tempname和class有一定的了解, 要明白他们在哪些方面不同, 哪些方面相同, 这样才能对体会到traits编程的核心. 如果你已经明 ...
- 洛谷——P4014 分配问题
P4014 分配问题 题目描述 有 nn 件工作要分配给 nn 个人做.第 ii 个人做第 jj 件工作产生的效益为 c_{ij}cij .试设计一个将 nn 件工作分配给 nn 个人做的分配方案, ...
- python数字取反~
>>> a = [1,2,3,4,5,7,6,4,2,10] >>> h = len(a)//2 >>> h 5 >>> ~h ...
- MySQL之中文乱码问题
创建 my.ini 文件,在该文件中添加以下内容,放在安装好的mysql根路径下: [client] default-character-set=utf8 [mysql] # 设置mysql客户端默认 ...