hdu 1423 GCIS 模板题

//GCIS

 1 #include "iostream"
 2 #include "cstdio"
 3 #include "cstring"
 4 #include "algorithm"
 5 using namespace std;
 6 int dp[510], Max;
 7 int s1[510], s2[510];
 8 int len1, len2;
 9
10 int main()
11 {
12     int T, i, j;
13     scanf("%d", &T);
14     while(T--) {
15         scanf("%d", &len1);
16         for(i = 1; i <= len1; ++i)
17             scanf("%d", &s1[i]);
18         scanf("%d", &len2);
19         for(i = 1; i <= len2; ++i)
20             scanf("%d", &s2[i]);
21         memset(dp, 0, sizeof(dp));
22         for(i = 1; i <= len1; ++i) {
23             Max = 0;
24             for(j = 1; j <= len2; ++j) {
25                 if(s1[i] > s2[j])
26                     Max = max(Max, dp[j]);
27                 else if(s1[i] == s2[j])
28                     dp[j] = max(dp[j], Max + 1);
29             }
30         }
31         int res = 0;
32         for(i = 1; i <= len2; ++i) {
33             res = max(res, dp[i]);
34         }
35         printf("%d\n", res);
36         if(T)
37             printf("\n");
38     }
39 }
时间: 2024-09-29 22:08:03

hdu 1423 GCIS 模板题的相关文章

Saving Princess claire_(hdu 4308 bfs模板题)

http://acm.hdu.edu.cn/showproblem.php?pid=4308 Saving Princess claire_ Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2305    Accepted Submission(s): 822 Problem Description Princess claire_ wa

hdu 1711 KMP模板题

// hdu 1711 KMP模板题 // 贴个KMP模板吧~~~ #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> using namespace std; const int MAX_N = 1000008; const int MAX_M = 10008; int T[MAX_N]; int p[MAX_M]; int f[MAX_M]; int

hdu 2586 LCA模板题(离线算法)

http://acm.hdu.edu.cn/showproblem.php?pid=2586 Problem Description There are n houses in the village and some bidirectional roads connecting them. Every day peole always like to ask like this "How far is it if I want to go from house A to house B&quo

HDU 1423 LICS 模板

http://acm.hdu.edu.cn/showproblem.php?pid=1423 4.LICS.O(lena * lenb) 设dp[i][j]表示a[]的前i项,以b[]的第j项结尾时,能匹配的最大值. ①.不匹配a[i]这个数,则是dp[i][j] = dp[i – 1][j]; ②.匹配a[i]这个数,则需要a[i] == b[j] && b[j] > b[k]   推出   dp[i][j] = max(dp[i – 1][k]) + 1, 这样复杂度需要O(n3

HDU 2586 LCA模板题

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2586 题目大意:在一个无向树上,求一条链权和. 解题思路: 0 | 1 /   \ 2      3 设dist[i]为i到根0的链和,求法(Dfs过程中dist[v]=dist[u]+e[i].w) 对于树中任意两点形成的链,可以通过LCA最近公共祖先剖分. 比如2->3,就可以经过LCA点1:  2->1->3 链和=dist[u]+dist[v]-2*dist[LCA[u,v]] (

hdu 2544 hdu 1874 Dijkstra 模板题

hdu 2544  求点1到点n的最短路 Sample Input2 1 //结点数 边数1 2 3 //u v w3 31 2 52 3 53 1 20 0 Sample Output32 1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <algorithm> 5 # include <cmath> 6 # define LL long

HDU 2087 kmp模板题

s为主串 t为模板串 求t的nextt 加const #include<stdio.h> #include<string.h> #include<algorithm> #include<map> #include<math.h> #include<queue> using namespace std; char s[1005]; char t[1005]; int nextt[1005]; void makenext(const ch

【网络流#3】hdu 1532 - Dinic模板题

输入为m,n表示m条边,n个结点 记下来m行,每行三个数,x,y,c表示x到y的边流量最大为c 这道题的模板来自于网络 http://blog.csdn.net/sprintfwater/article/details/7913061 建议大家去这个页面看看,博主也很良心地添加了很多注释 关于这个模板:Edge为前向星的边数,所以需要初始化Edge和head数组 n表示有n个点,这个版无所谓点从0开始还是从1开始,s表示源点,t表示汇点很好的一个是,这个版的DFS使用的是模拟栈,防止爆栈 1 #

hdu 3342 拓扑模板题

直接上代码吧 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int m,n,map[110][110],degree[110]; int topo() { int i,j,k,mark; for(i=0;i<m;i++) { mark=0; for(j=0;j<m;j++) { if(degree[j]==0) { mark=1; degree[j]=-