Luo Gu P1174 Arkanoid

Title Description

Little Red liked to play a game called Arkanoid, rules of the game are as follows:

In the beginning, there are NN n-rows × m \ Times m × bricks m columns, there are red KK K rounds. Each bullet can be red, a break in the lowermost column of the current row that the brick, and the corresponding score. (as the picture shows)

After some broken bricks, also possible to get a bullet rewards. Finally, when all the bricks are broken, red or no bullets, the game ends.

Red before the game starts, we already know each brick score after the break, and know can not get the bullet out of the reward. Alice wanted to know in this game she maximum possible score, but the problem is too difficult for her, can you help her?

Input Format

First line 33 is three positive integer, n-, m, KN, m, K n- , m , K. Indicates the start time, there NN n-rows × m \ Times m × bricks m columns, there are red KK K rounds.

Then there NN n-rows, each row of the format is as follows:

f1c1f2c2f3c3……fmcmf_1 c_1 f_2 c_2 f_3 c_3 …… f_m c_mf1c1f2c2f3c3fmcm

Wherein fif_i F i is a positive integer, it represents the line ii brick row i, the score after the break. cic_i C I a character, only two possibilities, YY the Y or NN N. YY the Y-expressed reward out of bullets, NN N means no.

All numbers between characters separated by a space, end of the line there is no extra spaces.

Output Format

Only a positive integer representing the maximum score.

Sample input and output

Input # 1
3 4 2 
9 N 5 N 1 N 8 N 
5 N 5 Y 5 N 5 N 
6 N 2 N 3 N 4 N
Output # 1
13

Description / Tips

For 20% 20 \% 2 0 % data satisfies 1 ≦ n, m≤5,1≤k≤101 \ n-Le, m \ Le 5,1 \ Le K \ Le 10 . 1 n- , m . 5 , . 1 K . 1 0, all characters CC C are NN N

For 50% 50 \% . 5 0 % data satisfies 1 ≦ n, m≤200,1≤k≤2001 \ n-Le, m \ 1/200, Le \ Le K \ Le 200 is . 1 n- , m 2 0 0 , . 1 K 2 0 0, all characters CC C are NN N

For 100% 100 \% . 1 0 0 % data satisfies 1 ≦ n, m≤200,1≤k≤2001 \ n-Le, m \ 1/200, Le \ Le K \ Le 200 is . 1 n- , m 2 0 0 , . 1 K 2 0 0, the character CC C may be YY the Y

For 100% 100 \% . 1 0 0 % of the data, all FF F value satisfies 1≤f≤100001 \ Le F \ 10000 Le . 1 F . 1 0 0 0 0

 

 

Look not very good solution to a problem, they write according to their own understanding.

First there is a prefix and, si [i] [j], sr [i] [j], si [i] [j] denotes the i-th column has j bullets and by the bullets can be obtained score, a ideal state. sr [i] [j] denotes the i-th column,

J can be obtained using the bullet points, an actual state.

Then dp equation. fi [i] [j], fr [i] [j] .fi [i] [j] denotes the front i column j by the bullets, and by the maximum score achievable when a bullet is an ideal state . fr [i] [j] denotes the front i columns,

The actual maximum points j bullet can get, which is not by bullets. So our final answer is fr [m] [k].

 

The code.

 

#include<bits/stdc++.h>
#define maxn 201 
using namespace std;
int fi[maxn][maxn];
int fr[maxn][maxn];
bool vis[maxn][maxn];
int si[maxn][maxn];
int sr[maxn][maxn];
int a[maxn][maxn];
int n,m,k;
int main()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            int w;
            char c[3];
            scanf("%d%s",&w,c);
            a[i][j]=w;
            if(c[0]=='Y') vis[i][j]=1;
        }
    }
    for(int i=1;i<=m;i++)
    {
        int cnt=0;
        for(int j=n;j>=1;j--)
        {
            if(vis[j][i])
                si[i][cnt]+=a[j][i];
            else
            {
                cnt++;
                si[i][cnt]=si[i][cnt-1]+a[j][i];
                sr[i][cnt]=si[i][cnt-1]+a[j][i];
            }
        }
    }
    for(int i=1;i<=m;i++)
    {
        for(int j=0;j<=k;j++)
        {
            for(int  p=0 ; P <= J && P <= n-; P ++ ) 
            { 
                Fi [I] [J] = max (Fi [I] [J], Fi [I- . 1 ] [JP] + Si [I] [P]) ;
                 iF (p) fr [I] [J] = max (fr [I] [J], Fi [I- . 1 ] [JP] + SR [I] [p]);
                 // if p is greater than 0, which means you can lend before the first i-1 Lie bullet
                 // make it into the actual maximum value from the maximum value of the ideal, in fact
                 // later before i-1 Lie kick is not consumed us p bullet i th column of the
                 // in still remaining bullet hit a p-i-th column, while the remaining bullet can only p
                 // reaches a practical maximum of the i-th column 
                IF (JP> 0 ) fr [I] [J] = max (fr [I] [J], fr [I- . 1 ] [JP] + Si [I] [P]);
                 //When jp is greater than zero, which means before the first i-1 column can lend a column i
                 // bullet, it becomes a practical maximum of the maximum value from the ideal, in fact,
                 // when after we finished first column i did not consume jp bullets in front of i-1 column
                 // (hit a Y, so the consumption side edge to get the bullet bullet) jp remaining bullets
                 // will only get the actual maximum value of the front row i-1 
            } 
        } 
    } 
    the printf ( " % D " , fr [m] [K]);
     return  0 ; 
}

 

 

Guess you like

Origin www.cnblogs.com/lee454207074/p/11613962.html