hdu 4512 吉哥系列故事——完美队形I LCIS
给一个数列, 在里面选出一些数组成一个对称的数列, 数的顺序不能打乱。 使得左半边是一个严格递增的数列, 右边递减, 并且a[i] = a[n-i+1]。
就是一个对称的LCIS..
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
int dp[], a[], b[];
int main()
{
int n, m, t;
cin>>t;
while(t--) {
cin>>n;
int ans = ;
for(int i = ; i<=n; i++) {
cin>>a[i];
b[n-i+] = a[i];
}
mem(dp);
for(int i = ; i<=n; i++) {
int best = ;
for(int j = ; j<=n-i+; j++) {
if(a[i]==b[j]) {
if(j == n-i+)
dp[j] = max(dp[j], dp[best]+);
else
dp[j] = max(dp[best]+, dp[j]);
} else if(a[i]>b[j]&&dp[j]>dp[best]) {
best = j;
}
if(dp[j]>ans)
ans = dp[j];
}
}
cout<<ans<<endl;
}
return ;
}
hdu 4512 吉哥系列故事——完美队形I LCIS的更多相关文章
- HDU 4512 吉哥系列故事——完美队形(LCIS)
Problem Description 吉哥这几天对队形比较感兴趣. 有一天,有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希望从中挑出一些人,让这些人形成一 ...
- hdu 4512 吉哥系列故事——完美队形I【LCIS经典应用】
链接: http://acm.hdu.edu.cn/showproblem.php?pid=4512 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- HDU 4512——吉哥系列故事——完美队形I——————【LCIS应用】
吉哥系列故事——完美队形I Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tot ...
- hdu 4512 吉哥系列故事——完美队形I_LCIS
题目链接 题意: 假设有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希望从中挑出一些人,让这些人形成一个新的队形,新的队形若满足以下三点要 求,则就是新 ...
- hdu 4512 吉哥系列故事——完美队形I(最长公共上升自序加强版)
首先要去学习最长公共上升子序列LCIS.然后是对n*n效率的算法进行优化,这里要注意的是能够求出来的序列中间能够有一个最高的.刚開始将输入的数组进行逆置,写下来发现这可能存在问题. 只是详细是什么也没 ...
- LCIS HDOJ 4512 吉哥系列故事——完美队形I
题目传送门 题意:中文题面 分析:LCIS应用:设置b[]为a[]的反转,然后LCIS,若相等的是自己本身,则+1, 否则+2 代码: #include <cstdio> #include ...
- HDU 4513 吉哥系列故事――完美队形II(Manacher)
题目链接:cid=70325#problem/V">[kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher V - 吉哥系列故事――完美队形I ...
- HDU 4513 吉哥系列故事――完美队形II
http://acm.hdu.edu.cn/showproblem.php?pid=4513 吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others) ...
- HDU 4513 吉哥系列故事——完美队形II manacher
吉哥系列故事——完美队形II Problem Description 吉哥又想出了一个新的完美队形游戏! 假设有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希 ...
随机推荐
- Linq to sql 实现多条件的动态查询(方法一)
/// <summary> /// Linq to sql 多字段动态查询 /// </summary> /// <returns></returns> ...
- sublime text 2中Windows下编写的脚本在Linux平台上运行遇到字符问题
今天在windows下的sublime text 2下写了个脚本,上传到ubuntu服务器中执行后提示: -bash: /usr/bin/python: /usr/bin/python^M: bad ...
- mysql学习(五)-字段属性
字段属性: unsigned: 无符号类型,只能修饰数值类型: create table if not exists t1(id int unsigned); zerofill:前端填0 //只能修饰 ...
- 关于Eclipse的编码配置和字体大小设置
编码设置 1.工作空间编码:Window-->Preferences-->General-->Workspace 2.工程文件编码:项目-->Properties-->R ...
- box-shadow 给图片添加内部阴影
box-shadow 是css3中定义的设置元素阴影的属性,其语法结构如下: <shadow> = inset? && <length>{2,4} && ...
- 初学swift笔记 函数(六)
import Foundation /* func 函数名 (参数名:参数类型) { } func 函数名 (参数名:参数类型) ->Void{ } func 函数名 (参数名:参数类型) -& ...
- MySQL----information-schema数据库相关权限的说明。
MySQL中的information_schema数据库比较特别有如下几个要注意的地方. 1.就算是一个新创建的用户,也就是说这个用户只有一个usage权限.它都可以查看informatoin_sch ...
- Oracle数据导入导出imp/exp(转)
在oracle安装目录下有EXP.EXE与IMP.EXE这2个文件,他们分别被用来执行数据库的导入导出.所以Oracle数据导入导出imp/exp就相当与oracle数据还原与备份. 一.Oracle ...
- 设置高级的Logstash 管道
设置高级的Logstash 管道: 一个Logstash 管道在很多实用例子有一个或者多个输入,filter,和output 插件. 本节中 创建Logstash 配置文件来指定那些插件和讨论每个插件 ...
- poj3673---双重for循环
#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX 15 int main ...