hdu 5904 LCIS (dp)
题意: 给定两个序列,求它们的最长公共递增子序列的长度, 并且这个子序列的值是连续的 思路:以值为连续做入手点。
很显然个鬼咯
dp[a[i]]表示以a[i]结尾的最大长度。
dp[a[i]] = dp[a[i-1]] + 1
对于b序列一样。
答案为 MAX(min(dp[i],dp2[i])) ( 1=<i <= 1E6)
1/* ***********************************************
2Author :111qqz
3Created Time :Mon 26 Sep 2016 04:02:24 AM CST
4File Name :code/hdu/5904.cpp
5************************************************ */
6#include <cstdio>
7#include <cstring>
8#include <iostream>
9#include <algorithm>
10#include <vector>
11#include <queue>
12#include <set>
13#include <map>
14#include <string>
15#include <cmath>
16#include <cstdlib>
17#include <ctime>
18#define fst first
19#define sec second
20#define lson l,m,rt<<1
21#define rson m+1,r,rt<<1|1
22#define ms(a,x) memset(a,x,sizeof(a))
23typedef long long LL;
24#define pi pair < int ,int >
25#define MP make_pair
26using namespace std;
27const double eps = 1E-8;
28const int dx4[4]={1,0,0,-1};
29const int dy4[4]={0,-1,1,0};
30const int inf = 0x3f3f3f3f;
31const int N=1E6+7;
32int dp[N],dp2[N];
33int n,m;
34int main()
35{
36 #ifndef ONLINE_JUDGE
37 freopen("code/in.txt","r",stdin);
38 #endif
39 int T;
40 scanf("%d",&T);
41 while (T--)
42 {
43 ms(dp,0);
44 ms(dp2,0);
45 scanf("%d%d",&n,&m);
46 int mx = 0;
47 for ( int i = 1 ; i <= n ; i++)
48 {
49 int x;
50 scanf("%d",&x);
51 dp[x] = dp[x-1] + 1;
52 mx = max(x,mx);
53 }
54 for ( int i = 1 ; i <= m ; i++)
55 {
56 int x;
57 scanf("%d",&x);
58 dp2[x] = dp2[x-1] + 1;
59 mx = max(x,mx);
60 }
61 int ans = 0 ;
62 for ( int i = 1 ; i <= mx ; i++) ans = max(ans,min(dp[i],dp2[i]));
63 printf("%d\n",ans);
64 }
65 #ifndef ONLINE_JUDGE
66 fclose(stdin);
67 #endif
68 return 0;
69}