填坑的时候又到啦,校赛因为不会LCIS所以吃了大亏,这里要补起来。LCIS就是在两个串里找最长上升子序列,相关的博客有很多,这里自己就不写那么多了。

http://www.cnblogs.com/jackge/archive/2013/05/16/3081793.html

http://www.cnblogs.com/gj-Acit/p/3236384.html

上面两个博客对于O(n^2)的做法讲解的比较详细,大家可以参考一下。

贴两记代码

HDU1423

#pragma warning(disable:4996)
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std; #define maxn 550
int a[maxn];
int b[maxn];
int n1, n2;;
int dp[maxn][maxn]; int main()
{
int T; cin >> T;
while (T--){
cin >> n1;
for (int i = 1; i <= n1; i++) scanf("%d", a + i);
cin >> n2;
for (int i = 1; i <= n2; i++) scanf("%d", b + i);
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n1; i++){
int tmp = 0;
for (int j = 1; j <= n2; j++){
dp[i][j] = dp[i - 1][j];
if (a[i] > b[j] && dp[i - 1][j] > tmp) tmp = dp[i - 1][j];
if (a[i] == b[j]) dp[i][j] = tmp + 1;
}
}
int ans = 0;
for (int i = 1; i <= n1; i++){
ans = max(ans, dp[n1][i]);
}
printf("%d\n", ans);
if (T) puts("");
}
return 0;
}

HDU4512

#pragma warning(disable:4996)
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std; #define maxn 550 int a[maxn];
int b[maxn];
int n;
int dp[maxn][maxn]; int main()
{
int T; cin >> T;
while (T--)
{
cin >> n;
for (int i = 1; i <= n; i++){
scanf("%d", a + i);
b[n + 1 - i] = a[i];
}
int ans = 0;
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; i++){
int tmp = 0;
for (int j = 1; j <= n+1-i; j++){
dp[i][j] = dp[i - 1][j];
if (a[i] > b[j] && dp[i - 1][j] > tmp) tmp = dp[i - 1][j];
if (a[i] == b[j]){
dp[i][j] = max(dp[i][j],tmp + 1);
}
if (i < n + 1 - j) ans = max(ans, dp[i][j] * 2);
else ans = max(ans, dp[i][j] * 2 - 1);
}
}
printf("%d\n", ans);
}
return 0;
}

HDU4512完美队形I && HDU1423 Greatest Common Increasing Subsequence (LCIS)的更多相关文章

  1. HDU 1423 Greatest Common Increasing Subsequence LCIS

    题目链接: 题目 Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...

  2. HDU1423 Greatest Common Increasing Subsequence

    题意 如标题. \(|s1|,|s2| \leq 500\) 分析 既然是dp问题的组合,那么考虑dp. 定义状态f(i,j)表示对第一个序列s1的前i个和第二个序列s2的前j个元素求最长上升公共子序 ...

  3. HDU1423 Greatest Common Increasing Subsequence (DP优化)

    LIS和LCS的结合. 容易写出方程,复杂度是nm2,但我们可以去掉一层没有必要的枚举,用一个变量val记录前一阶段的最优解,这样优化成nm. 1<=k<j,j增加1,k的上界也增加1,就 ...

  4. HDU1423:Greatest Common Increasing Subsequence(LICS)

    Problem Description This is a problem from ZOJ 2432.To make it easyer,you just need output the lengt ...

  5. Greatest Common Increasing Subsequence hdu1423

    Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536 ...

  6. POJ 2127 Greatest Common Increasing Subsequence -- 动态规划

    题目地址:http://poj.org/problem?id=2127 Description You are given two sequences of integer numbers. Writ ...

  7. HDOJ 1423 Greatest Common Increasing Subsequence -- 动态规划

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1423 Problem Description This is a problem from ZOJ 2 ...

  8. ZOJ 2432 Greatest Common Increasing Subsequence(最长公共上升子序列+路径打印)

    Greatest Common Increasing Subsequence 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problem ...

  9. HDU 1423 Greatest Common Increasing Subsequence(最长公共上升LCIS)

    HDU 1423 Greatest Common Increasing Subsequence(最长公共上升LCIS) http://acm.hdu.edu.cn/showproblem.php?pi ...

随机推荐

  1. [原创]PostgreSQL中十进制、二进制、十六进制之间的相互转换

    在PostgreSQL中,二进制.十进制.十六进制之间的转换是非常方便的,如下: 十进制转十六进制和二进制 mydb=# SELECT to_hex(10); to_hex -------- a (1 ...

  2. poj 2046 Gap

    题目连接 http://poj.org/problem?id=2046 Gap Description Let's play a card game called Gap. You have 28 c ...

  3. CPU制造工艺 级选来决定cpu等级

    CPU制造工艺 编辑 CPU制造工艺又叫做CPU制程,它的先进与否决定了CPU的性能优劣.CPU的制造是一项极为复杂的过程,当今世上只有少数几家厂商具备研发和生产CPU的能力.CPU的发展史也可以看作 ...

  4. 关于DataSource的一些记录

    今天看WWDC的232_hd_advanced_user_interfaces_with_collection_views,里面花了一般的时间来讲如何合理的设计程序的datesource,将的很有道理 ...

  5. 初识MVC,MVC里面的基本数据传递

          MVC是一种表现形式,他将Web应用程序分成三个组件即:视图(View)控制器(Controller)模型(Model). M:Model 主要是存储或者是处理数据的组件 V:View 是 ...

  6. 颜色之RGBA

    颜色之RGBA RGB是一种色彩标准,是由红(R).绿(G).蓝(B)的变化以及相互叠加来得到各式各样的颜色.RGBA是在RGB的基础上增加了控制alpha透明度的参数. 语法: color:rgba ...

  7. Liferay IDE 3.1 M1发布啦

    很嗨森,以后就再也不用SDK和下载.ivy啦 新增功能主要有: 1.Liferay Workspace(用来存放Liferay Module项目) 2. Liferay Gradle Module P ...

  8. 一些常用到的Centos命令

    CentOS常用命令在我们的使用中,经常被使用.所以,我们对一些经常使用又很重要的CentOS常用命令进行了全面的整理.下面,就来介绍这些CentOS常用命令. 一:使用CentOS常用命令查看cpu ...

  9. Careercup - Google面试题 - 6253551042953216

    2014-05-06 01:49 题目链接 原题: Modify the following code to add a row number for each line is printed pub ...

  10. 常用EXE文件反编译工具

    PE Explorer V1.99 R5 绿色汉化特别版_强大的可视化汉化集成工具 功能极为强大的可视化汉化集成工具,可直接浏览.修改软件资源,包括菜单.对话框.字符串表等: 另外,还具备有 W32D ...