题意:题意就是坑,看不大懂么,结果就做不对,如果看懂了就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. Gradle 语法

    参考文章: Gradle学习系列之二——创建Task的多种方法(http://www.cnblogs.com/CloudTeng/p/3417970.html) Gradle基本知识点与常用配置(ht ...

  2. 面试题-------SSL协议简介

    SSL协议简介 SSL简介 Secure Socket Layer,为Netscape所研发,用以保障在Internet上数据传输之安全,利用数据加密(Encryption)技术,可确保数据在网络上之 ...

  3. c语言使用librdkafka库实现kafka的生产和消费实例(转)

    关于librdkafka库的介绍,可以参考kafka的c/c++高性能客户端librdkafka简介,本文使用librdkafka库来进行kafka的简单的生产.消费 一.producer librd ...

  4. subnet partition

    例1:本例通过子网数来划分子网,未考虑主机数. 一家集团公司有12家子公司,每家子公司又有4个部门.上级给出一个172.16.0.0/16的网段,让给每家子公司以及子公司的部门分配网段. 思路:既然有 ...

  5. springboot+jsp 遇到的坑

    springboot  使用jsp: 1,修改配置文件, spring: mvc: view: prefix: /WEB-INF/jsp/ suffix: .jsp 2,pom 加入: <dep ...

  6. js中对话框的使用

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  7. oracle老是出现监听错误

    解决方法之一: 点击开始-->选择程序--->选中你安装的oracle版本-->选中配置与移植工具-->选中Net Configuration Assistant-->在 ...

  8. console.log等不能打印全部数据/信息

    有时候console.log在chrome调试控制台打印不全,如下: 这个时候,我们可以点击进去:用watch 工具,添加变量,右击copy value 选项:

  9. SpringBoot yml properties文件

    一.在SpringBoot实现属性注入: 1).添加pom依赖jar包: 1 <!-- 支持 @ConfigurationProperties 注解 --> 2 <!-- https ...

  10. python3 django连接mysql,同步表结构

    第一步:安装PyMySQ代替MySQLdb pip3 install PyMySQL 然后在工程目录的__init__.py中填写下面两句话   import pymysql pymysql.inst ...