History Grading_lcs

原创 2018年04月17日 21:54:50

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 tex2html_wrap_inline34 as tex2html_wrap_inline36 where tex2html_wrap_inline38 denotes the ranking of event i in the correct chronological order and a sequence of student responses tex2html_wrap_inline42 where tex2html_wrap_inline44 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 tex2html_wrap_inline50 . The second line will contain nintegers, indicating the correct chronological order of n events. The remaining lines will each consist of n integers with each line representing a student's chronological ordering of the n events. All lines will contain n numbers in the range tex2html_wrap_inline60 , 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
#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int N=30;
int s[N],t[N];
int dp[N][N]={0};
int main(){
   //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n,k;
    cin>>n;
    for(int i=1;i<=n;i++){
        scanf("%d",&k);
        s[k]=i;
    }
    while(~scanf("%d",&k)){
        t[k]=1;
        for(int i=2;i<=n;i++){
            scanf("%d",&k);
            t[k]=i;
        }
        //printf("gg\n");
        for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        if(s[i]==t[j])dp[i][j]=dp[i-1][j-1]+1;
        else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);

        printf("%d\n",dp[n][n]);
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ujn20161222/article/details/79981544

HTML5新特性之History

几年前,Ajax的兴起给互联网带来了新的生机,同时也使用户体验有了质的飞跃,用户无需刷新页面即可获取新的数据,而页面也以一种更具有交互性的形式为用户展现视图,可以说这种变化对互联网发展的贡献是史无前例...
  • liuhe688
  • liuhe688
  • 2015-04-23 23:21:17
  • 4383

history命令保存的最大数?

怎样修改history最大保留数呢? history命令保存的最大数? Linux 怎样修改history最大保留数呢? linux历史命令默认条数是1000 history命令保留的默认...
  • sz_bdqn
  • sz_bdqn
  • 2015-06-17 01:56:05
  • 2202

关于JavaScript的history对象的方法的使用

代码示例如下: =================================               history对象    /*   history对象存储访问过的页面...
  • u010661782
  • u010661782
  • 2015-10-10 10:59:21
  • 628

ubuntu history 命令详解

ubuntu history 命令详解 ...
  • sdfgh2046
  • sdfgh2046
  • 2010-03-13 10:35:00
  • 10347

Linux下查看history里的某种命令

Linux下,直接键入history命令,会将当前账户此前所有的命令都显示出来,w
  • leftfist
  • leftfist
  • 2014-11-21 10:49:42
  • 4119

Bash Shell 中的History命令

###  Bash Shell 中的History命令 ---------- 日常运维工作中,我们经常使用History命令去检查在这台机器上所执行的历史命令,或者谁在什么时间执行的什么命令。H...
  • doctor_who2004
  • doctor_who2004
  • 2015-08-08 12:45:13
  • 2048

不记录history及清除history

临时生效export HISTCONTROL=ignorespace 执行命令时最前面加上空格即可。 清除所有记录 >./bash/_history ...
  • u012700515
  • u012700515
  • 2015-08-11 12:52:51
  • 858

关于HTML5 的history API介绍与使用

上一篇我们介绍了H5的营销,那么H5的营销必然会设计到一些技术性的问题,那么本篇我们就介绍H5的一些新型特性。首先我们来了解下history及其改变:大家都知道history即浏览器的历史记录,我们访...
  • wh_forever
  • wh_forever
  • 2015-11-26 19:58:33
  • 7012

如何给history命令记录加上时间戳

在问题定位时,我们有时需要查看history命令记录,看是否有删除/移动文件、修改配置等误操作,为history命令添上时间记录,可便于分析、定位问题。   默认的情况下,history执行结果显...
  • zj0910
  • zj0910
  • 2014-11-19 19:28:57
  • 2114

history.js使用方法(来自博客园)

Ajax保留浏览器历史的解决方案 ul class="menu"> li>a href="/home/index#page=1">page1a>li> li>a href="/home/in...
  • shuawanxiao
  • shuawanxiao
  • 2015-01-11 17:33:00
  • 20601
收藏助手
不良信息举报
您举报文章:History Grading_lcs
举报原因:
原因补充:

(最多只允许输入30个字)