编程介的小学生 2018-11-27 17:27 采纳率: 20.5%
浏览 379
已采纳

分类输出结果的一个问题,请问大神有什么好办法,用C语言编程

Problem Description
``There is no denying the clues. They are clearly there; you can't miss them. But are we interpreting the clues correctly? That is where the author tricks us. There are most definitely more than one way to look at a clue and what it signifies, but the way the author has laid them out, (like a breadcrumb trail) we are inclined to believe they lead us to the end conclusion . . ."

You have been reading Harry Potter series for some time. Since the final book will not be out in the store until 2007, and you are curious about what could happen in the final book of the series, you have decided to do some guessing by yourself. After rereading the series for some days, you have divided every piece of information you currently have into three categories:

A.
Extracts. Extracts are taken from the previous published books in the series, and you don't need to check for their validities;
B.
Assumptions. Assumptions are based on different interpretations of other assumptions / extracts from the books. An assumption is plausible if and only if some of the assumptions (or extracts from the book) this assumption relies on are interpreted in ways that support this assumption. No assumption requires itself to be plausible, whether directly or indirectly.
C.
Theories. Theories are based on extracts and assumptions. If all the extracts and assumptions one theory depends on are believable and interpreted to support this theory, then we say this theory can be argued as believable.

Note that extracts and assumptions may have many different exclusive explanations leading to other theories and/or assumptions.

Because of personal preferences, you want to see some scenes in the next book come true much more than the others, thus you have assigned different values to different theories, each being an exponent of 2, less or equal to 2(number of theories-1) . You want to know what the maximal possible value of theories that can be argued as believable at the same time is; furthermore, since the less guesswork you do, the more reliable your theories are, you are interested in the minimum number of explanations you must make to make all those theories acceptable. Can you accomplish this seemingly impossible task?

Input
The input consists of several cases, each followed by a blank line.

Each test case starts with three integers N , M and K (1<=N<=1000, 1<=M<=5000, 1<=K<=100) , the number of extracts from the book, the number of assumptions and the number of theories, respectively.

The following part describes extracts and assumptions. Extracts are always described before assumptions. Each description starts with one string S , the name of the extract / assumption, and an integer T in the next line, the number of different explanations you have come up with; T lines follow, on each line there is a string X , the explanation which leads to another assumption / theory.

The next part of test case consists of K descriptions of theories. Each description starts with one string S , the name of the theory, followed by one integer P , the value which you have assigned to this theory.

Two successive descriptions are separated by a line with one single character `-'. It is guaranteed that the total numbers of explanations which extracts and assumptions have does not exceed 50000, and you may assume every string's length is less or equal to 20, and only consists of letters from alphabet and numbers 0...9 .

N = 0 , M = 0 , K = 0 indicates the end of input file and should not be processed by your program.

Output
For every test case, output the maximum value followed by the minimum number of explanations you have to make in the format as indicated in the sample output. Print all the plausible theories (with the maximum total value) on the following lines. Separate the result of two successive inputs with one blank line.

Explanation for Sample Input / Output

In order to make Theory1 believable, Extract1, Extract2, Assumption1, and Assumption3's explanations must be Assumption1, Assumption3, Theory1 and Theory1, respectively. Thus the total number of explanations we must make is 4.

Sample Input
2 3 1
Extract1
2
Assumption1

Assumption2

Extract2
2
Assumption2

Assumption3

Assumption1
2
Assumption2

Theory1

Assumption2

0

Assumption3
1

Theory1

Theory1
1

0 0 0

Sample Output
Case 1:
1
4
Theory1

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-02-13 00:16
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 Python安装cvxpy库出问题
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题