Hdu 1904 LCIS (dp)
来源:互联网 发布:绝地求生大逃杀优化差 编辑:程序博客网 时间:2024/06/12 10:42
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5904
题目大意:
给定两个串a,b,长度分别为n与m,求两个串的最长公共上升子序列,且子序列的值连续
分析:
直接做显然不好做,选择dp[i]表示以i结尾的连续递增子序列的长度,dp[a[i]] = dp[a[i]-1]+1,i从1遍历到n,即可得到一个串的所有子序列,得到两个串的子序列后,遍历每个子序列,两个串的相同结尾的子序列长度取最小值,然后找最大值即可
代码:
#include <cstdio>#include <cstring>#include <string>#include <iostream>#include <algorithm>using namespace std;int a[120000],b[120000],dpa[2100000],dpb[2100000];int main(){ int T,n,m; scanf("%d",&T); while (T--) { int maxn = 0 ; scanf("%d%d",&n,&m); for (int i = 1 ; i <= n ; i ++) { scanf("%d",&a[i]); maxn = max(maxn,a[i]); } for (int i = 1 ; i <= m ; i ++) { scanf("%d",&b[i]); maxn = max(maxn,b[i]); } for (int i = 0 ; i <=maxn ; i ++) { dpa[i] = 0; dpb[i] = 0; } int ans=0; for (int i = 1 ; i <= n ; i ++) dpa[a[i]] = dpa[ a[i] - 1 ] + 1 ; for (int i = 1 ; i <= m ; i ++) dpb[b[i]] = dpb[ b[i] - 1 ] + 1 ; for (int i = 0 ; i <= maxn ; i ++) ans = max(ans,min(dpa[i],dpb[i])); printf("%d\n",ans); }}
阅读全文
0 0
- Hdu 1904 LCIS (dp)
- 【HDU 5904 LCIS + dp】
- HDU-5904 LCIS(dp)
- HDU 5904 LCIS (DP)
- HDU 5904 LCIS (dp)
- hdu 5904 LCIS【dp】
- HDU 5904 LCIS __ dp、LCIS
- hdu 5904 LCIS(简单dp)
- HDU 5904 LCIS(dp)
- HDU --- 5904 LCIS 【思维 + 简单dp】
- HDU 5904:LCIS(LCIS)
- hdu5904 LCIS(dp)
- hdu5904LCIS(LCIS+DP)
- hdu5904 LCIS dp
- HDU5904 LCIS (DP)
- hdu 3308 LCIS
- hdu 3308 LCIS
- HDU 4512 LCIS
- java.util.concurrent包图文源码解析(一)——CountDownLatch
- 数组元素循环右移问题
- x86,x64,Debug,release在VS中的编译如何选择
- 【JavaScript】—— 一键上传插件
- ubuntu下安装jenkins
- Hdu 1904 LCIS (dp)
- c++常对象和常成员函数详解
- 洛谷P1107 最大整数
- codeforces828C
- ubuntu 16.04安装opencv3.0流程以及报错解决
- 欢迎使用CSDN-markdown编辑器
- NEC协议红外遥控器
- ubuntu环境下降低gcc和g++的版本
- POJ_3278 Catch That Cow