UVa 111 - History Grading

题目:历史上有一些事件发生的先后顺序,现在有很多学生写了不同的顺序表,

判断每个学生的最大的前后顺序正确的序列。

分析:dp,LIS,最大上升子序列。

注意本题的数据格式,串里的每个元素对应于:对应下标编号的事件在表中的位置;

状态:F(n)记录以第n个元素为结束元素的序列的最长上升子序列,有转移方程:

F(n)= max(F(i)+1)  { 其中 0 < i < n 且 data[i] < data[n] }。

说明:发现好多dp题(⊙_⊙)。

#include <iostream>
#include <cstdlib>

using namespace std;

int A[22],B[22],L[22];

int main()
{
	int n,t;
	cin >> n;
	for (int i = 1 ; i <= n ; ++ i)
		cin >> A[i];
	while (cin >>t) {
		B[t] = 1;
		for (int i = 2 ; i <= n ; ++ i) {
			cin >> t;
			B[t] = i;
		}

		for (int i = 1 ; i <= n ; ++ i) {
			L[i] = 1;
			for (int j = 1 ; j < i ; ++ j)
				if (A[B[j]] < A[B[i]] && L[j] >= L[i])
					L[i] = L[j]+1;
		}

		int max = 0;
		for (int i = 1 ; i <= n ; ++ i)
			if (max < L[i])
				max = L[i];

		cout << max << endl;
	}
	return 0;
}
时间: 2024-08-06 03:24:03

UVa 111 - History Grading的相关文章

uva 111 History Grading(DP初步应用)

uva 111 History Grading Many problems in Computer Science involve maximizing some measure according to constraints. Consider a history exam in which students are asked to put several historical events into chronological order. Students who order all

UVA 111 History Grading (最长公共子序列)

History Grading Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Background Many problems in Computer Science involve maximizing some measure according to constraints. Consider a history exam in which students are asked to put s

uva 111 - History Grading (dp, LCS)

题目链接 题意:给N,第二行是答案,n个数c1---cn, 代表第一个的顺序是c1,第二个数顺序是c2; 下面每一行是学生的答案,格式同上. 注意:这个给的顺序需要处理一下,不能直接用. 思路:LCS. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <algorithm> 6 using namespac

UVA 111 History Grading 【lcs】

Brief Description: 一个历史考试,有n个历史事件, 它们之间的年份是不同的,要学生把这些事件按照正确的顺序排列出来.有两种记分方式,采用的是第二种: 假设有历史事件1,2,3,4, 它们正确的时间顺序是1,2,3,4, 然后假设学生的答案是1,3,2,4, 那么按照相对顺序正确的数量,答对了三个(1,2,4或者1,3,4),也就是它与正确答案的最长公共子序列长度是3,便是答对的数量. Analyse: 最长公共子序列模板题,但是这题的输入是个很大的坑,他的输入是按照顺序,事件1

uva 101 History Grading

Background Many problems in Computer Science involve maximizing some measure according to constraints. Consider a history exam in which students are asked to put several historical events into chronological order. Students who order all the events co

History Grading

uva111:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=47 题意:看懂之后就是求两个串的最长公共子串. 题解:不过这里要注意一下,就是题目中假如说第一个数是2,表示事件1应该放在第二个位子,这样转化一下就可以了.以前集训的时候也搞过这样的东西,但是年代久远,往事早已随风而去.今天复习了一下,发现很简单的

uva111 History Grading

History Grading Description Background Many problems in Computer Science involve maximizing some measure according to constraints. Consider a history exam in which students are asked to put several historical events into chronological order. Students

[uva] 1671 History of Languages

题目描述 输入两个DFA,判断是否等价. https://uva.onlinejudge.org/external/16/1671.pdf 输入 第一行T 可以接受的字母表 第二行N 状态数 接下去N行 每个状态的情况 第一个表示是否为接受状态 后面T个是接受字母i可以转移到的状态 -1表示不转移 输出 等价输出Yes,不等价输出No 样例输入 2 3 1 -1 1 0 -1 2 0 -1 0 2 1 -1 1 0 -1 0 3 4 1 -1 -1 1 1 -1 -1 2 1 -1 -1 3 1

UVA 111 简单DP 但是有坑

题目传送门:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18201 其实是一道不算难的DP,但是搞了好久,才发现原来是题目没读清楚,囧,原序列那里简直太坑了, 看了别人好多的都是用最长公共子序列,但是我用的是最长上升子序列来做,就是将原序列逐渐递增映射成递增的数列,这道题目的数据恰好符合这个条件 比如正确的序列为$$5 \ 6 \ 4  \ 1 \  3 \  2$$,我就可以将他一一映射成为 $$ID[5]\right