HDU 1423 —— Greatest Common Increasing Subsequence
2016-03-13 21:19
435 查看
原题:http://acm.hdu.edu.cn/showproblem.php?pid=1423
题意:求最长上升公共子序列的个数;
注意:每组数据之间要空一行,最后一组数据结束不需要空行;
题意:求最长上升公共子序列的个数;
注意:每组数据之间要空一行,最后一组数据结束不需要空行;
#include<cstdio> #include<cstring> #include<string> #include<algorithm> using namespace std; const int maxn = 510; int cas, n, m; int dp[maxn][maxn]; int a[maxn], b[maxn]; int main() { scanf("%d", &cas); while(cas--) { memset(dp, 0, sizeof dp); scanf("%d", &n); for(int i = 1;i<=n;i++) scanf("%d", &a[i]); scanf("%d", &m); for(int i = 1;i<=m;i++) scanf("%d", &b[i]); for(int i = 1;i<=n;i++) { int tmp = 0; for(int j = 1;j<=m;j++) { dp[i][j] = dp[i-1][j]; if(b[j] < a[i] && tmp < dp[i-1][j]) tmp = dp[i-1][j]; if(a[i] == b[j]) dp[i][j] = tmp + 1; } } int ans = -1; for(int i = 1;i<=m;i++) ans = max(ans, dp [i]); printf("%d\n", ans); if(cas != 0) printf("\n"); } return 0; }
相关文章推荐
- iOS开发UI篇—核心动画(基础动画)
- iOS开发UI篇—核心动画简介
- ContentResolver的四个常用方法:delete().query(),update(),insert()
- LC115 Distinct Subsequences
- leetcode:Permutation Sequence
- codeforces 3D . Least Cost Bracket Sequence 贪心
- CodeForces 622A--F - Infinite Sequence
- 用UIToolBar实现简单毛玻璃效果
- POJ1947 Rebuilding Roads(树形DP)
- stl之适配器容器——stack, queue, priority_queue
- stl之序列容器——deque
- 利用UIImageJPEGRepresentation与UIGraphicsBeginImageContext进行图片压缩的简单比较
- 优先队列(Priority Queue)
- LeetCode 之 Unique Paths
- 63. Unique Paths II
- Android spannableStringBuilder用法整理
- UVA1152 4 Values whose Sum is 0
- GUI布局
- Penguins DbTools数据库管理移植差分工具(EXCEL相关) ver 20160313
- android studio 报Error:failed to find Build Tools revision XXXX