省选PKU查漏补缺专题训练

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

NOI省队第三轮选拔赛-图论算法专题训练试题

[第八组]

【题目一览】

Pigs

【问题描述】

Mirko works on a pig farm that consists of M locked pig-houses and Mirko can't unlock any pighouse because he doesn't have the keys. Customers come to the farm one after another. Each of them has keys to some pig-houses and wants to buy a certain number of pigs.

All data concerning customers planning to visit the farm on that particular day are available to Mirko early in the morning so that he can make a sales-plan in order to maximize the number of pigs sold.

More precisely, the procedure is as following: the customer arives, opens all pig-houses to which he has the key, Mirko sells a certain number of pigs from all the unlocked pig-houses to him, and, if Mirko wants, he can redistribute the remaining pigs across the unlocked pig-houses.

An unlimited number of pigs can be placed in every pig-house.

Write a program that will find the maximum number of pigs that he can sell on that day.

【输入格式】

The first line of input contains two integers M and N, 1<=M<=1000, 1<=N<=100, number of pighouses and number of customers. Pig houses are numbered from 1to M and customers are numbered

from 1 to N.

The next line contains M integeres, for each pig-house initial number of pigs. The number of pigs in each pig-house is greater or equal to 0 and less or equal to 1000.

The next N lines contains records about the customers in the following form (record about the i-th customer is written in the (i+2)-th line):

A K1 K2 …K A B

It means that this customer has key to the pig-houses marked with the numbers K1, K2, …, K A (sorted nondecreasingly) and that he wants to buy B pigs. Numbers A and B can be equal to 0.

【输出格式】

The first and only line of the output should contain the number of sold pigs.

【输入输出样例】

输入:

3 3

3 1 10

2 1 2 2

2 1

3 3

1 2 6

输出:

7

Life Forms

【问题描述】

You may have wondered why most extraterrestrial life forms resemble humans, differing by superficial traits such as height, colour, wrinkles, ears, eyebrows and the like. A few bear no human resemblance; these typically have geometric or amorphous shapes like cubes, oil slicks or clouds of dust.

The answer is given in the 146th episode of Star Trek - The Next Generation, titled The Chase. It turns out that in the vast majority of the quadrant's life forms ended up with a large fragment of common DNA.

Given the DNA sequences of several life forms represented as strings of letters, you are to find the longest substring that is shared by more than half of them.

【输入格式】

Standard input contains several test cases. Each test case begins with 1<=n<=100, the number of life forms. n lines follow; each contains a string of lower case letters representing the DNA sequence of a life form. Each DNA sequence contains at least one and not more than 1000letters.

A line containing 0 follows the last test case.

相关文档
最新文档