Logo
(追記) (追記ここまで)

12126번 - Merlin QA (Large) 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 512 MB82353345.205%

문제

Edythe is a young sorceress working in the quality assurance department of Merlin, Inc. -- a magic spell factory. Her job is to test the magic spells that Merlin himself invents. Each spell requires precise amounts of certain ingredients and transforms them into other amounts of other ingredients. Edythe's job is to cast each spell exactly once in order to verify that the spell works correctly.

She can cast a spell only if she has the required amount of each ingredient. If she has already created ingredients of the right type from previous spells, Edythe must use those first. However, if she still needs more ingredients, she is allowed to take them from Merlin's storehouse. She has no ingredients to start with, but at the end, she gets to keep all the extra ingredients that she created and didn't use.

Edythe wants to make as much profit as possible from her apprenticeship! She has to cast each of the N given spells exactly once, but she is free to do so in any order. Assuming that each spell works as expected, which ordering lets her earn the most money in the end?

For example, imagine that the test plan contains the following 3 spells:

  1. Inputs: \7ドル worth of gold. Outputs: \5ドル worth of sulfur.
  2. Inputs: nothing. Outputs: \10ドル worth of gold, \10ドル worth of sulfur.
  3. Inputs: \3ドル worth of gold, \20ドル worth of sulfur. Outputs: \2ドル worth of toads.

Note that the first spell converts gold into sulfur, the second spell conjures up gold and sulfur from nothing, and the third spell converts gold and sulfur into toads.

If Edythe were to cast these spells in the order 1, 2, 3, then she would start by fetching \7ドル worth of gold from the storehouse for spell #1. That would let her cast spells #1 and #2, giving her \10ドル worth of gold and \15ドル worth of sulfur. For the final spell, she would need \3ドル worth of gold and \20ドル worth of sulfur. She would have to use all of the sulfur she created so far, \3ドル worth of gold, and \5ドル more worth of sulfur that she fetched from the storehouse. This would leave her with \9ドル worth of ingredients at the end (\7ドル worth of gold and \2ドル worth of toads).

But there is a better plan. If she cast the spells in the order 3, 1, 2, she would have \27ドル worth of ingredients at the end (\10ドル worth of gold, \15ドル worth of sulfur, and \2ドル worth of toads).

입력

The first line of the input gives the number of test cases, T. T test cases follow. Each one starts with a line containing N and M. M is the number of kinds of ingredients in the world. Each of the next N lines contains M integers describing a spell. Each integer is the value (or cost) of the corresponding ingredient. Negative integers are the dollar costs of the input ingredients; positive integers are the dollar values of the output ingredients; and zeros denote ingredients that are neither produced nor consumed by the spell. This also implies that no spell can simultaneously consume and produce the same ingredient.

Limits

  • 1 ≤ T ≤ 100.
  • 1 ≤ N ≤ 100.
  • -100 ≤ Each integer in each spell ≤ 100.
  • 1 ≤ M ≤ 8.

출력

For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is the largest value of ingredients Edythe can have at the end.

제한

예제 입력 1

2
3 1
1
0
-1
3 3
-7 5 0
10 10 0
3 -20 2

예제 출력 1

Case #1: 1
Case #2: 27

힌트

출처

Contest > Google > Code Jam > Google Code Jam 2015 > World Finals E2번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /