题意:题意就是坑,看不大懂么,结果就做不对,如果看懂了就so easy了,给定n个事件,注意的是,

它给的是第i个事件发生在第多少位,并不是像我们想的,第i位是哪个事件,举个例子吧,4 2 3 1,

表示的是第一个事件发生在第四,第二个事件发生在第二位,第三个在第三位,第四个在第一位。

然后输入n个答案,求有多少个事件相对位置是和原来一样的。

那么知道输入好办了,我们只需对输入做一下预处理,就变成了LIS。

代码如下:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstring>
#include <map> using namespace std;
const int maxn = 20 + 5;
int d[maxn], a[maxn], id[maxn]; int main(){
int n, x; cin >> n;
for(int i = 1; i <= n; ++i){
scanf("%d", &x);
id[i] = x;//第i个事件发生在第x位
} while(~scanf("%d", &x)){
a[0] = -10;
a[x] = id[1];
for(int i = 2; i <= n; ++i){
scanf("%d", &x);
a[x] = id[i];//查找第x个事件编号是几
} memset(d, 0, sizeof(d));
int m = 0;
for(int i = 1; i <= n; ++i){//LIS
for(int j = 0; j < i; ++j)
if(a[i] > a[j] && d[j]+1 > d[i]) d[i] = d[j] + 1;
m = max(m, d[i]);
} printf("%d\n", m);
} return 0;
}

网上大数都是用LCS做,其实都差不多。

用LCS代码如下:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstring>
#include <map> using namespace std;
const int maxn = 20 + 5;
int d[maxn][maxn], a[maxn], id[maxn]; int main(){
int n, x; cin >> n;
for(int i = 1; i <= n; ++i){
scanf("%d", &x);
id[x] = i;
} while(~scanf("%d", &x)){
a[0] = -10;
a[x] = 1;
// a[x] = id[1];
for(int i = 2; i <= n; ++i){
scanf("%d", &x);
a[x] = i;
// a[x] = id[i];
} memset(d, 0, sizeof(d));
int m = 0;
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j)
if(id[i] == a[j]) d[i][j] = d[i-1][j-1] + 1;
else d[i][j] = max(d[i-1][j], d[i][j-1]);
// m = max(m, d[i]);
} printf("%d\n", d[n][n]);
} return 0;
}

UVa 111 History Grading (简单DP,LIS或LCS)的更多相关文章

  1. uva 111 History Grading(最长公共子序列)

    题目连接:111 - History Grading 题目大意:给出一个n 代表序列中元素的个数, 然后是一个答案, 接下来是若干个同学的答案(直到文件结束为止), 求出两个序列的最长公共子序列, 注 ...

  2. UVa 111 - History Grading (by 最长公共子序列 )

     History Grading  Background Many problems in Computer Science involve maximizing some measure accor ...

  3. uva 111 - History Grading (dp, LCS)

    题目链接 题意:给N,第二行是答案,n个数c1---cn, 代表第一个的顺序是c1,第二个数顺序是c2; 下面每一行是学生的答案,格式同上. 注意:这个给的顺序需要处理一下,不能直接用. 思路:LCS ...

  4. uva 111 History Grading(lcs)

    题目描述 在信息科学中有一些是关于在某些条件限制下,找出一些计算的最大值. 以历史考试来说好了,学生被要求对一些历史事件根据其发生的年代顺序来排列.所有事件顺序都正确的学生无疑的可以得满分.但是那些没 ...

  5. UVA 111 History Grading

    读题读了好久,其实就是在输入数据时要对数据的位置进行相应的改变 #include<iostream> #include<cstring> #include<cstdio& ...

  6. UVA - 11584 划分字符串的回文串子串; 简单dp

    /** 链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34398 UVA - 11584 划分字符串的回文串子串: 简单 ...

  7. UVA 111 (复习dp, 14.07.09)

     History Grading  Background Many problems in Computer Science involve maximizing some measure accor ...

  8. UVA 10003 Cutting Sticks 区间DP+记忆化搜索

    UVA 10003 Cutting Sticks+区间DP 纵有疾风起 题目大意 有一个长为L的木棍,木棍中间有n个切点.每次切割的费用为当前木棍的长度.求切割木棍的最小费用 输入输出 第一行是木棍的 ...

  9. 洛谷P1130红牌(简单DP)

    题目描述 某地临时居民想获得长期居住权就必须申请拿到红牌.获得红牌的过程是相当复杂 ,一共包括NNN个步骤.每一步骤都由政府的某个工作人员负责检查你所提交的材料是否符合条件.为了加快进程,每一步政府都 ...

随机推荐

  1. 迷你MVVM框架 avalonjs 学习教程17、avalon的一些配置项

    本章节,主要是介绍avalon.config方法,通过它来制定一些更贴心的功能. 一般情况下,我们在使用ms-controller绑定时,需要添加一个ms-controller类名,目的是为了防止网速 ...

  2. Java学习 第二节

    1.非递归求第四十个斐波那契数 package test; public class fibonacci2 { public static void main(String arg[]) { ; ; ...

  3. SQL获取分组后取某字段最大一条记录(求每个类别中最大的值的列表)

    获取分组后取某字段最大一条记录 方法一:(效率最高) select * from test as a where typeindex = (select max(b.typeindex) from t ...

  4. python -m

    影响sys.path python xxx.py python -m xxx.py 这是两种加载py文件的方式:1叫做直接运行2把模块当作脚本来启动 直接启动是把脚本所在的目录放到了sys.path属 ...

  5. Mysql update 一个表中自己的数据

    update  table ucf, table t2 set ucf.pcid = t2.pcid where t2.name = 'liming' and t2.gid= ucf.gid and ...

  6. Spring ThreadPoolTaskExecutor

    1. ThreadPoolTaskExecutor配置 1 <!-- spring thread pool executor --> 2 <bean id="taskExe ...

  7. SearchEngine Note

    [SearchEngine Note] 1.查全率. 2.查准率. 3.查全率与查准率的关系. 4.四大系统. 5.权威性网页反向链接多.网页的平均出席为25.7,即平均每一个网页含有25.7个指向其 ...

  8. 每月IT摘录201805

    摘录自互联网的前辈心得: 一.技术:0.精通一个淘汰的技术对你没有任何价值.学习的精力有限,更应该花在值得学的技术上.比如网络.操作系统.数据结构.算法1.工作要有定力,更多的应该是关心问题如何更有效 ...

  9. Java label

    标号label提供了一种简单的break语句所不能实现的控制循环的方法.当你嵌套在几层循环中想退出循环时,break只能退出一重循环,可以用标号标出想退出哪一个语句. 标号的命名不能以"_& ...

  10. 用HttpClient发送HTTPS请求报SSLException: Certificate for <域名> doesn't match any of the subject alternative names问题的解决

    最近用server酱-PushBear做消息自动推送,用apache HttpClient做https的get请求,但是代码上到服务器端就报javax.net.ssl.SSLException: Ce ...