编程介的小学生 2018-12-12 09:49 采纳率: 0.9%
浏览 444
已采纳

现场求助C语言大身来解决下这个算法难题,关键是怎么计算的思路

Problem Description
Magina, also known as Anti-Mage, is a very cool hero in DotA (Defense of the Ancient).

If you have no idea of him, here is some brief introduction of his legendary antecedents:
Twin sons to the great Prophet, Terrorblade and Magina were blessed with divine powers: Terrorblade granted with an unnatural affinity with life forces; Magina gifted with energy manipulation. Magina's eventual overexposure to the magic gradually augmented his elemental resistances and bestowed him the unique ability to move faster than light itself. Now, broken by Terrorblade's fall to the dark side, Magina answers the Sentinel's call in a desperate bid to redeem his brother. Every bitter strike turns the Scourge's evil essences upon themselves, culminating in a finale that forces his enemy to awaken to the void within and spontaneously implode.
Magina has a very IMBA (imbalanced) skill – Blink, yes, move from one place to another place in a wink. Our problem begins at there.
As a formidable hero in the later stage, Magina always farm with the wild monsters for a long time. To make the farming more efficient, Magina use Blink frequently to jump here and there. Here we assume Blink skill has no CD, that is, we can use this skill at any time we want.
There are N spots of the wild monsters, and Magina can choose any one to begin. For every spots, Magina may use Ti time to kill the monsters and gain Gi units money, or he choose blink to other spots, which is known to our brilliant Magina. If the monsters in a spot were killed, it won’t appear any more.
Now Magina want to get M units money to but some excellent equipment, say Battle Fury for example. As a hero to save the world, there is no much time left for Magina, he wonders the minimum time for him to gain at least M units money.

Input
The first line contains a single integer T, indicating the number of test cases.
Each test case begins with two integers N, M. Their meanings are the same as the description.
Then N blocks follow, each one describes a spot of wild monsters.
The first line of each block is there integers Ti, Gi and Ki. Ti is the time, Gi is the units of money, Ki is the number of spots Magina can blink to from here.
Then Ki integer Cij follow, indicating the spots’ ID Magina can blink to. You may assume no ID would appear twice.
The spots are described with ID increasing from 1 to N. Input ensure if you can blink from i to j, you can also blink from j to i.

Technical Specification

  1. 1 <= T <= 50
  2. 1 <= N <= 50
  3. 1 <= Ti <= 10000000
  4. 1 <= M, Gi <= 1000000000
  5. 1 <= Ki < N
  6. 1 <= Cij <= N

Output
For each test case, output the case number first, then the minimum time for Magina to gain at least M units money, if can’t, output “Poor Magina, you can't save the world all the time!”.

Sample Input
3
1 4
2 5 0
1 5
1 4 0
4 10
1 9 0
3 3 1
3
3 3 2
2 4
4 4 1
3

Sample Output
Case 1: 2
Case 2: Poor Magina, you can't save the world all the time!
Case 3: 10

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-06-30 10:14
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵