UVA - 111 History Grading
来源:互联网 发布:clojure编程 编辑:程序博客网 时间:2024/04/29 03:14
题目大意:给出一个 n 代表序列中元素的个数, 然后是一个答案, 接下来是若干个同学的答案(直到文件结束为止), 求出两个序列的最长公共子序列, 注意给出的答案均是以该事件处于第几个发生的, 例如 :2 3 4 1
即是 对应第1个事件在第2个发生,第2个事件在第3个发生 ...转换一下就是 4 1 2 3
解题思路:最长公共子序列问题, 状态转移方程
0 ( i == 0 || j == 0)
d[i][j] = d[i - 1] [j - 1] + 1 ( a[i] == b[i])
max(d[i - 1][j] , d[i] [j - 1]) ( a[i] != b[i])
#include <iostream>using namespace std;int main() {int n, temp, A[25], B[25], DP[25][25] = {0};cin >> n;for (int i = 1; i <= n; i++) {cin >> temp;A[temp] = i;}while (cin >> temp) {B[temp] = 1;for (int i = 2; i <= n; i++) {cin >> temp;B[temp] = 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;elseDP[i][j] = max(DP[i][j-1], DP[i-1][j]);cout << DP[n][n] << endl;}return 0;}
0 0
- UVa 111 - History Grading
- uva 111 History Grading
- [UVA 111] History Grading
- uva:111 - History Grading
- UVa 111 - History Grading
- UVa 111 - History Grading
- UVA 111 History Grading
- UVa 111 - History Grading
- Uva - 111 - History Grading
- UVa 111 - History Grading
- UVa 111 - History Grading
- Uva-111-History Grading
- UVa 111: History Grading
- UVA - 111 History Grading
- UVA 111 History Grading
- uva 111History Grading
- UVA 111 History Grading
- UVA-111 History Grading
- Android——JSON数据解析详解
- iOS CoreBluetooth 教程蓝牙技术
- java面试之异常捕获
- 中国震惊超算界 ISC13华中科技大学HPL夺冠
- impdp ORA-00001: unique constraint (SYS.I_JOB_JOB) violated
- UVA - 111 History Grading
- spring 注解配置定时器
- WiFi影盘教你解决手机内存 留住一个肾
- jquery插件大全
- 这是我的程序员之路的开始,以此为我以后做一个激励和标志
- c语言整数表示
- Swift 编程语言入门教程
- linq介绍
- android与WEB服务器交互时,如何保证在同一个会话Session中通信