#P1174. 打砖块

打砖块

Description

Xiaohong really likes to play a game called Brick Breaker. The rules are as follows:

At the beginning, there are nn rows and mm columns of bricks, and Xiaohong has kk bullets. Each time, she can spend one bullet to break the brick that is currently at the bottom of some chosen column, and gain the corresponding score (as shown in the figure).

Some bricks, after being broken, may also award one bonus bullet. The game ends when all bricks are broken or when Xiaohong has no bullets left.

Before the game starts, Xiaohong already knows the score obtained by breaking each brick and whether it awards a bonus bullet. She wants to know the maximum possible total score she can achieve in this game, but this problem is too difficult for her. Can you help her?

Input Format

The first line contains 3 positive integers, n,m,kn,m,k. They indicate that initially there are nn rows and mm columns of bricks, and Xiaohong has kk bullets.

Next there are nn lines, each in the following format:
f1 c1 f2 c2 f3 c3fm cmf_1~c_1~f_2~c_2~f_3~c_3\cdots f_m~c_m

Here fif_i is a positive integer, denoting the score of the brick in row ii and the chosen column after it is broken. cic_i is a character with only two possibilities, Y or N. Y indicates a bonus bullet is awarded, and N indicates none.

All numbers and characters are separated by a single space, and there are no extra spaces at the end of a line.

Output Format

Output a single positive integer, the maximum total score.

3 4 2
9 N 5 N 1 N 8 N
5 N 5 Y 5 N 5 N
6 N 2 N 4 N 3 N
13

Hint

For 20% of testdata, 1n,m51 \le n,m \le 5, 1k101 \le k \le 10, and all characters cc are N.

For 50% of testdata, 1n,m2001 \le n,m \le 200, 1k2001 \le k \le 200, and all characters cc are N.

For 100% of testdata, 1n,m2001 \le n,m \le 200, 1k2001 \le k \le 200, and characters cc may be Y.

For 100% of testdata, all ff satisfy 1f100001 \le f \le 10000.

Translated by ChatGPT 5