【DP】UVA 111 History Grading
2014-08-31 20:38
337 查看
输入的序列是表示 ai的位置上值为 i
然后就是最长公共子序列
然后就是最长公共子序列
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <string> #include <iostream> #include <algorithm> using namespace std; #include <queue> #include <stack> #include <vector> #include <deque> #include <set> #include <map> #define IN freopen ("in.txt" , "r" , stdin); #define OUT freopen ("out.txt" , "w" , stdout); typedef long long LL; const int MAXN = 2111;//点数的最大值 const int MAXM = 20006;//边数的最大值 const int INF = 11521204; const int mod=1000000007; int a[44],b[44],dp[44][44]; int main() { int n,x; //IN; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&x); a[x]=i; } while(~scanf("%d",&x)) { b[x]=1; memset(dp,0,sizeof(dp)); for(int i=2;i<=n;i++) { scanf("%d",&x); b[x]=i; } for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if(a[i]==b[j]) dp[i][j]=dp[i-1][j-1]+1; else dp[i][j]=max(dp[i-1][j],dp[i][j-1]); } } printf("%d\n",dp ); } return 0; }
相关文章推荐
- UVa 111 History Grading (DP&LCS)
- UVA 111 History Grading(最长公共子序列dp)
- (DP6.1.4.1)UVA 111 History Grading(最长递增子序列LIS 的LCS 解法)
- 【解题报告】uva111_History Grading(历史考试, dp, LCS)
- uva 111 History Grading(DP初步应用)
- uva 111 - History Grading (dp, LCS)
- dp 最长公共子序列 uva 111-History Grading
- UVa 111 History Grading (简单DP,LIS或LCS)
- UVA111 History Grading 简单的DP
- 【DP】UVA 111 History Grading
- UVA-111 History Grading(dp+最长公共子序列)
- 序列代码UVa 111 History Grading (最长公共子序列)
- UVA 111 History Grading (最长公共子序列)
- UVA 111 History Grading
- History Grading - UVa 111 最长公共子序列 注意序列输入
- UVA 111 History Grading 【lcs】
- Uva 111 – History Grading
- [DP动归]-UVA-111-历史考试
- uva 111 History Grading(动态规划——最长公共子序列)
- UVA - 111 History Grading (动态规划:LCS)