编程介的小学生 2017-04-09 09:09 采纳率: 20.5%
浏览 1037
已采纳

Zombies VS Plants

Description

Facer was addicted to a popular game called "Plants VS Zombies". After Facer had completed all missions, he started to play the zombies' role to destroy plants and called the new game "Zombies VS Plants".

In the game "Zombies VS Plants", there are 3 kinds of zombies: Little Zombie, Adult Zombie and Football player. Different zombies have different price and different "attacking value" indicating the capability to attack, as shown in the table below:

Zombie name Attacking value Price for one (in dollars)
Little Zombie 40 50
Adult Zombie 70 75
Football player 200 100
Spiders also can destroy the plants. Every spider costs 125 dollars.

There are 4 kinds of plants: Sunflower, Bean, Magnet and Lettuce. Every plant has a "defending value" indicating it's capability of defense.

Facer's mission is to destroy ALL the plants in the field. In order to destroy plants, Facer needs to buy zombies or spiders and put them into the field. The plants field can be considered as a 5*5 grid(of course 25 cells), as shown in the figure below:

Plants field

There is a plant in every cell. Facer can destroy plants only by two ways:

If Facer puts one or more zombies together into a row of the field, and the sum of those zombies' attacking values is larger than the sum of defending values of the plants in the same row, all plants in that row will be destroyed.
Putting a spider in a cell will destroy the plant in it. But there are some exceptions as shown in the description of plant "Lettuce" in a table below.
Once a zombie is put into the plants field, it dies immediately after destroying the plants. So does a spider. In other words, Facer can use a zombie or a spider only once.

This is a table describing the features of different kinds of plants:

Plant name

Defending value

Special features

Sunflower

0

None

Bean

100

None

Magnet

0

A magnet can make the attacking value of the football players in the same row and the adjacent rows become 50. For example, if there is a magnet in row 3, the attacking value of all football players Facer put into row 2, 3 and 4 will become 50.

Lettuce

0

Spiders can't destroy a lettuce and the plants in the eight cells around the lettuce. For example, if there is a lettuce at cell (3,3), spiders can't destroy the lettuce and the plants in (2,2), (2,3), (2,4), (3,2), (3,4), (4,2), (4,3) and (4,4).

Facer can earn P1 dollars after destroying a row of plants, and destroying a sunflower will earn extra P2 dollars for him. Facer has P3 dollars but no zombies and no spiders at the begging. Of course Facer can use the money he earned to buy zombies and spiders.

Your job is helping Facer to accomplish his mission and keep money as much as possible after the mission.

Input

There are multiple test cases.
The first line in the input is a integer T indicating the number of test cases.( 1< T <= 400 )

For each test case:
First line contains three integers P1, P2 and P3 ( 0 <= P1, P2, P3 <= 10000), meaning that Facer earns P1 dollars after destroying a row of plants and earns P2 dollars after destroying a sunflower, and Facer has P3 dollars at the beginning.
Following are 5 lines describing the plants field by top to bottom order. Each line contains 5 integers, telling what's in the cells of a row, by left to right order. For those 5 integers:
"1" represents a sunflower.
"2" represents a bean.
"3" represents a magnet.
"4" represents a lettuce.
Output

For each test case, output one line containing an integer indicating the maximum amount of dollars Facer can keep after he accomplishes the mission. If Facer can't destroy all the plants, print -1 instead.

Sample Input

2
100 100 10000
2 2 2 2 2
2 3 2 2 2
3 3 4 3 2
2 3 2 2 2
2 2 2 2 2
0 0 0
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
Sample Output

9025
-1

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-04-23 15:50
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算