题意:题意就是坑,看不大懂么,结果就做不对,如果看懂了就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. 前端-CSS-6-盒子模型

    上面的布局宽度div{ width: 200px; height: 200px; border: 10px solid red; padding: 20px; } ------------------ ...

  2. css兼容性记录

    *        , ie6,ie7可以识别: _和- ,  ie6可以识别: !important  ,表示高优先级,ie7及以上,firefox都支持,ie6认识带!important的样式属性, ...

  3. ubuntu16.04 dpkg强制安装 teamviewer

    dpkg遇到安装有依赖,而依赖的包有无法安装的时候,可以试试强制安装: .90154_amd64.deb 虽然报错,但是安装后还是可以使用. 如果使用: .90154_amd64.deb 提示下面错误 ...

  4. linux 安装禅道

    1. 查看Linux服务器版本信息 # cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) 2. 禅道开源版安装包下载 # wge ...

  5. struts2 模拟令牌机制防止表单重复提交

    web.xml: <?xml version="1.0" encoding="UTF-8"?><web-app version="3 ...

  6. Containerpilot 配置文件 之 Telemetry

    如果提供telemetry选项,ContainerPilot将公开可用于刮擦性能telemetry的Prometheus HTTP客户端界面. telemetry接口被公告为consul服务. tel ...

  7. spring-boot PageHelper

    分页插件PageHelper 参看了pagehelper-spring-boot,使用起来非常放方便,关于更多PageHelper可以点击https://github.com/pagehelper/M ...

  8. 正向工程configuration配置连接

    在执行正向工程的时候需要用到这个关键词里面的configure();方法, 这个方法有好几个重构, 都是参数不一样的, 也可以空着不写, 不写的话就会默认去找hibernate.cfg.xml这个文件 ...

  9. 一些常用的c++系统函数

    数学<cmath><math.h>: 1 三角函数 double sin (double); double cos (double); double tan (double); ...

  10. compression

    compression - 必应词典 美[kəmˈpreʃ(ə)n]英[kəm'preʃ(ə)n] n.压缩:加压:压紧:浓缩 网络压迫:压力:加压包扎