原题连接

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=114&page=show_problem&problem=47

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 correctly will receive full credit, but how should partial credit be awarded to students who incorrectly rank one or more of the historical events?

Some possibilities for partial credit include:

  1. 1 point for each event whose rank matches its correct rank
  2. 1 point for each event in the longest (not necessarily contiguous) sequence of events which are in the correct order relative to each other.

For example, if four events are correctly ordered 1 2 3 4 then the order 1 3 2 4 would receive a score of 2 using the first method (events 1 and 4 are correctly ranked) and a score of 3 using the second method (event sequences 1 2 4 and 1 3 4 are both in the correct order relative to each other).

In this problem you are asked to write a program to score such questions using the second method.

The Problem

Given the correct chronological order of n events  as  where  denotes the ranking of eventi in the correct chronological order and a sequence of student responses  where  denotes the chronological rank given by the student to event i; determine the length of the longest (not necessarily contiguous) sequence of events in the student responses that are in the correct chronological order relative to each other.

The Input

The first line of the input will consist of one integer n indicating the number of events with  . The second line will contain n integers, indicating the correct chronological order of n events. The remaining lines will each consist of nintegers with each line representing a student's chronological ordering of the n events. All lines will contain n numbers in the range  , with each number appearing exactly once per line, and with each number separated from other numbers on the same line by one or more spaces.

The Output

For each student ranking of events your program should print the score for that ranking. There should be one line of output for each student ranking.

Sample Input 1

4
4 2 3 1
1 3 2 4
3 2 1 4
2 3 4 1

Sample Output 1

1
2
3

Sample Input 2

10
3 1 2 4 9 5 10 6 8 7
1 2 3 4 5 6 7 8 9 10
4 7 2 3 10 6 9 1 5 8
3 1 2 4 9 5 10 6 8 7
2 10 1 3 8 4 9 5 7 6

Sample Output 2

6
5
10
9

【题目大意】

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

反正题目我是没看懂,谷歌翻译了一下午都是懵的,然后直接搜题解写博客的时候就把解释照搬了大佬的

https://blog.csdn.net/shuangde800/article/details/7880532



题目的坑点就在于翻译软件都翻不出来准确的意思。。。
举个栗子
4
4 2 3 1
1 3 2 4
3 2 1 4
2 3 4 1
第一个样例的第一行其实是指第一个事件在第四个发生,第二个事件在第二个发生
并不是直接输入数组进行字符串匹配= =
除了输入之外,其实就是一个LCS的板子,我按照平常的LCS的思路写样例都过不了23333

一道在输入上有坑点的LCS的更多相关文章

  1. Appium和Robotium在文字输入上的区别

    Appium和Robotium在文字输入上的区别   Appium和Robotium在对文本框进行输入时有一定的区别: Appium在输入文字时需要调用系统键盘 Robotium在输入文字是根本不需要 ...

  2. URLencode 特殊字符 转义 遇上的坑

    在项目中遇到一个问题,在webveiw和原生之间进行传值的时候,出现了一些encode的小问题.看起来很简单的问题,实际上却存在不小的坑. 首先说一下目前项目的结构,在一个activity中,webv ...

  3. POJ 2472 106 miles to Chicago(Dijstra变形——史上最坑的最长路问题)

    题目链接 :http://poj.org/problem?id=2472 Description In the movie "Blues Brothers", the orphan ...

  4. 史上巨坑: vim的"set foldmethod=syntax"设置竟然是导致ctrl+p(ctrl+n)补全在文件稍大时光标位于中间位置补全效率变慢的元凶!

    最近我的vim又让我闹心了. 问题出现在supertab的补全速度上, 有时候按下tab键半天才弹出补全列表, 即便是弹出了列表在列表上下移动也变得的相当缓慢, 这让我的很是蛋疼. 在完全无法接受这个 ...

  5. 关于windows nginx不能启动问题的解决,史上最坑系列之一(原文)

    我是直接在官方网址下载windows1.6稳定版的nginx,之所以下载它是因为在window下方便学习,更好的在linux安装和学习nginx. 下载到D:\nginx学习\,解压它,并进入启动它 ...

  6. 前端坑多:使用js模拟按键输入的踩坑记录

    坑 一开始在Google搜索了一番,找到了用jQuery的方案,代码量很少,看起来很美好很不错,结果,根本没用-- 我反复试了这几个版本: var e = $.Event('keyup') e.key ...

  7. 帮朋友 解决一道 LeetCode QJ上问题

    引言 对于刷题,自己是没能力的. 最经一个朋友同事考我一道数组题 . 也许能当面试分享吧. 娱乐娱乐. 事情的开始是这样的. 前言 题目 截图 大概意思 是 在一个 数组中,找出其中两个不重复出现的元 ...

  8. redis bind连不上的坑

    由于需要在内网其他服务器上连接redis服务器(192.168.1.110),本想直接在redis配置文件中加上目标的IP地址: bind 192.168.1.166 就可以了,实际上不正确. red ...

  9. iOS 上传自己的工程(模块工具类)到cocoapods上遇到坑

    最近在研究把自己写的工具类和模块上传到cocoapods上, 再新构建项目中可以直接使用cocoapods使用  也可以更新之前的版本 便于维护项目. 但是在这个过程中遇到了种种问题 但是最后还是解决 ...

随机推荐

  1. python3 函数的参数

    函数的参数 形参(函数定义时) + 实参(函数调用时) 形参:形式参数 在函数的定义处定义的参数,比如def func(参数1, 参数2, 参数3...) 普通参数(位置参数), 默认参数,普通收集参 ...

  2. Spring Cloud Alibaba生态探索:Dubbo、Nacos及Sentinel的完美结合

    @ 目录 背景 一.项目框架 1.1 采用IDEA和Maven多模块进行项目搭建 1.2 模块管理及版本管理 二.微服务公共接口 2.1 定义一个公共接口Api 2.2 pom.xml 2.3 Goo ...

  3. 实战Docker容器调度

    目录 一.前言 二.Docker Compose 2.1.简介 2.2.下载安装 2.3.小实验 2.4.小实验的细节 2.5.Compose file的编写规则 三.Docker Swarm 3.1 ...

  4. GitLab集成kubernetes

    创建GitLab源码项目并上传示例代码 1. 创建GitLab源码项目 本示例中创建的GitLab源码项目地址为:https://gitee.com/SunHarvey/helloworld_java ...

  5. 科普-- 白话HTTPS

    HTTPS是传输协议吗? HTTPS与HTTP有什么关系? HTTPS为什么会安全? 闲扯一下 Mac笔记本.Windows台式机.Linux主机.像这三种类型,它们硬件不同,系统不同,服务端处理的编 ...

  6. Java单播、组播(多播)、广播的简单实现

    简介 单播有TCP和UDP两种实现,组播(多播)和广播只有UDP一种实现.单播和广播基本一样,只是广播的数据包IP为广播IP.   单播 DatagramSocket和DatagramPacket 服 ...

  7. 028 01 Android 零基础入门 01 Java基础语法 03 Java运算符 08 逻辑“或”运算符

    028 01 Android 零基础入门 01 Java基础语法 03 Java运算符 08 逻辑"或"运算符 本文知识点:Java中的逻辑"或"运算符 逻辑& ...

  8. 《C++primerplus》第6章练习题

    本来前面五题都做完了,写博客时没保存好草稿= =,写了个整合版的程序,实现前五题的关键部分. 1.定义一个叫jojo的结构,存储姓名.替身和力量值,使用动态结构数组初始化二乔.承太郎和乔鲁诺乔巴纳等人 ...

  9. Android Studio3.5在编译项目出现连接不上gradle该怎么办?

    ------------恢复内容开始------------ 报错原因: Could not get resource 'https://dl.google.com/dl/android/maven2 ...

  10. Mysql的Sql语句优化

    在Mysql中执行Sql语句经常会遇到有的语句执行时间特别长的情况,出现了这种情况我们就需要静下心分析分析. 首先,我们需要确定系统中哪些语句执行时间比较长.这个可以使用Mysql的慢日志来跟踪.下面 ...