【HDOJ】1423 Greatest Common Increasing Subsequence
2015-01-16 12:30
363 查看
LCIS
/* 1423 */ #include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 505 int a[MAXN]; int b[MAXN]; int c[MAXN]; int n, m; int ans; int max(int a, int b) { return a>b ? a:b; } void solve() { int i, j, k; memset(c, 0, sizeof(c)); for (i=0; i<n; ++i) { k = 0; for (j=0; j<m; ++j) { if (a[i] == b[j]) { c[j] = max(c[j], k+1); } if (a[i] > b[j]) { k = max(k, c[j]); } } } ans = -1; for (i=0; i<m; ++i) ans = max(ans, c[i]); } int main() { int t; int i, j, k; #ifndef ONLINE_JUDGE freopen("data.in", "r", stdin); #endif scanf("%d", &t); while (t--) { scanf("%d", &n); for (i=0; i<n; ++i) scanf("%d", &a[i]); scanf("%d", &m); for (i=0; i<m; ++i) scanf("%d", &b[i]); solve(); printf("%d\n", ans); if (t) printf("\n"); } return 0; }
相关文章推荐
- HDOJ 1423 Greatest Common Increasing Subsequence -- 动态规划
- zoj 2432 && hdoj 1423 Greatest Common Increasing Subsequence 【打印LCIS】
- hdoj problem 1423 Greatest Common Increasing Subsequence (动态规划)
- HDOJ 题目1423 Greatest Common Increasing Subsequence(LICS)
- hdoj 1423 Greatest Common Increasing Subsequence(最长上升公共子序列)
- HDOJ 1423 Greatest Common Increasing Subsequence -- 动态规划
- HDOJ 1423 Greatest Common Increasing Subsequence 【DP】【最长公共上升子序列】
- HDOJ Greatest Common Increasing Subsequence(LCIS最长公共上升子序列)
- Greatest Common Increasing Subsequence poj-1423
- HDU 1423 Greatest Common Increasing Subsequence
- HDU 1423 Greatest Common Increasing Subsequence
- HDUOJ ---1423 Greatest Common Increasing Subsequence(LCS)
- hdu 1423 Greatest Common Increasing Subsequence(DP 最长公共上升子序列)
- hdu 1423 Greatest Common Increasing Subsequence
- HDU 1423 Greatest Common Increasing Subsequence(单调递增公共子序列)
- hdu 1423 Greatest Common Increasing Subsequence(最长公共上升子序列dp)
- HDU 1423 Greatest Common Increasing Subsequence
- hdu 1423 Greatest Common Increasing Subsequence(DP 最长公共上升子序列)
- hdu 1423 Greatest Common Increasing Subsequence(最长公共递增子序列lcis)
- 1423 Greatest Common Increasing Subsequence (LCIS)