hdu 1423 Greatest Common Increasing Subsequence(最长公共递增子序列lcis)
来源:互联网 发布:福州技术支持一九网络 编辑:程序博客网 时间:2024/05/22 04:14
求最长公共上升序列
dp[j] 表示B串中以j结尾的最长公共递增子序列
所以更新的时候当扫到A串的第i个数时,遍历B数组,找到小于A[i]且dp[j] 最大的数的位置x,判断当满足a[i]==b[j]时,则更新dp[j]=dp[x]+1。
代码:
#include<iostream>#include<stdio.h>#include<math.h>#include<algorithm>#include<string.h>#include<string>#include<ctime>#include<queue>#include<list>#include<map>#define INF 9999999#define MAXN 10000using namespace std;int dp[550];//b数组到第j个数字时,该数字位置处的公共递增因子数int main(){ int t; cin>>t; while(t--) { int n,m; cin>>n; int i,j,a[550],b[550]; for(i=0;i<n;i++) cin>>a[i]; cin>>m; for(i=0;i<m;i++) cin>>b[i]; memset(dp,0,sizeof(dp)); for(i=0;i<n;i++) { int x=0; for(j=0;j<m;j++) { if(a[i]>b[j]&&dp[j]>dp[x]) x=j; if(a[i]==b[j]) dp[j]=dp[x]+1; //dp[k]值+1就为当前字符的公共递增因子数 } } int ans=-1; for(i=0;i<m;i++) if(ans<dp[i]) ans=dp[i]; cout<<ans<<endl; if(t) cout<<endl; } return 0;}
0 0
- hdu 1423 Greatest Common Increasing Subsequence(最长公共递增子序列lcis)
- hdu 1423 Greatest Common Increasing Subsequence(最长公共上升子序列、LCIS)
- HDU 1423 Greatest Common Increasing Subsequence 最长公共递增序列
- hdu 1423 Greatest Common Increasing Subsequence(最长公共递增子序列LICS)
- Greatest Common Increasing Subsequence hdu1423 最长公共递增子序列
- HDU 1423 Greatest Common Increasing Subsequence(最长公共上升LCIS)
- HDOJ Greatest Common Increasing Subsequence(LCIS最长公共上升子序列)
- 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 (最长公共上升子序列)【模板】
- poj 2127 Greatest Common Increasing Subsequence (最长公共递增子序列)
- Greatest Common Increasing Subsequence(最长单调递增公共子序列+hdu1423)
- 最长单调递增公共子序列(路径记录+poj2127+zoj2432)Greatest Common Increasing Subsequence
- hdu1423 Greatest Common Increasing Subsequence(最长递增公共子序列)
- HDU1423 Greatest Common Increasing Subsequence(最长公共递增子序列)
- HDU 1423 Greatest Common Increasing Subsequence(最长公共子序列+最长不下降子序列)
- 新版JQuery Mobile返回按钮
- P122.17
- input IDC
- [leetcode]Balanced Binary Tree
- Getting iWork for Free on Older Macs
- hdu 1423 Greatest Common Increasing Subsequence(最长公共递增子序列lcis)
- 第8周项目3(1)分数类中的运算符重载
- 美好时光之大四下学期实验室实习
- HDOJ Calculation 2 3501(eular函数)
- java解惑--跨包方法覆写
- 使用JDBC对数据库进行CRUD(二)
- Linux怎么清空与删除指定大小文件
- 关于socket绑定INADDR_ANY
- sql效率