填坑的时候又到啦,校赛因为不会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. SQL 集合(笔记)

    ——SQL是关于集合的 oracle是关系型数据,其中的数据表都是有一定规律的数据的一个个集合,所以在使用SQL时,如果能按照集合的思路来进行时会节省很多效率,也鞥让语句更加的清晰明了. 1.四个集合 ...

  2. GraphLab面向机器学习的并行框架『针对图数据处理模型』

    最近在做文本处理知识的梳理,关注了CMU提出的GraphLab开源分布式计算系统 这是关于GraphLab的PPT:Distributed GraphLab『 http://cheng-qihang- ...

  3. angularjs+nodejs+mongodb三件套

    说实话,自己对于web前段的认识并不是太深入,但是因为项目的需要,所以有的时候肯定会需要接触到web前段的知识点.说到web前端想必大家肯定会想到css+js+html,的确web前端的工作,从某总角 ...

  4. Golang的Semicolons

    Semicolons The formal grammar uses semicolons ";" as terminators in a number of production ...

  5. UITableView 表视图编辑

    UITableViewController(表视图控制器)继承自UIViewController,自带一个tableView self.view不是UIView而是UITableView dataso ...

  6. java数据结构和算法------堆排序

    package iYou.neugle.sort; public class Heap_sort { public static void HeapSort(double[] array) { for ...

  7. Chr()和chrb()的含义(转)

    http://blog.csdn.net/cunxiyuan108/article/details/5989701 Chr(charcode) 必要的 charcode 参数是一个用来识别某字符的 L ...

  8. VC++编程中获取系统时间

    <span style="white-space:pre"> </span>总结了在程序中如何获得系统时间的方法 void CGetSystenTimeDl ...

  9. VC++ MFC 如何实现在编辑框中输出具有换行功能的文段 01

    很久不来写东西了,昨天睡觉前写个小工具,突然,这玩意不会换行怎么整... 首先是第一步,获取字符串的长度,转载自白乔的文章. ------------------------------------- ...

  10. 代码复用 -- 深入了解javascript

    /* 代码复用 */ /* 一.避免 */ /* 模式1:默认模式 */ function Parent() { this.name = "123"; } Parent.proto ...