P1541 Tortoise Chess Topic background
Xiao Ming's birthday, his father gave him a pair of turtle chess as a gift.
Title Description
The chess board is a row of n squares, one score per lattice (non-negative integer). The 1th grid is the only starting point, nth grid is the end, the game requires the player to control a turtle piece from the starting point to go to the end.
The M-card crawl card in Tortoise chess, divided into 4 different types (m card does not necessarily contain all 4 types of cards, see sample), each type of card is labeled with 1, 2, 3, 44 digits, indicating that after the use of this card, the turtle pieces will crawl forward the corresponding number of squares. In the game, each time the player needs to select a crawl card from all the crawl cards, and control the corresponding number of the turtle pieces forward, each card can only be used once.
In the game, the turtle piece automatically obtains the starting point lattice the fraction, and in the subsequent crawl each arrives a lattice, obtains the corresponding score of the lattice. The player's final game score is the sum of all the squares of the turtle pieces from the beginning to the end of the process.
Obviously, the use of different crawl cards in the order will make the final game score different, Xiaoming wants to find a card in order to make the final game score the most.
Now, tell the score of each lattice on the board and all the crawling cards, can you tell xiaoming how many points he can get?
Input/output format
Input format:
The input file is separated by a space between two numbers in each line.
The 1th row 2 positive integers n and M, respectively, representing the number of checkerboard squares and creeping cards.
The 2nd row n non-negative integers, a1a2......an, where AI represents the score on the first lattice of the chessboard.
The 3rd line m integer, B1B2......BM, represents the number on the M-card crawl card.
The input data guarantees that the M-card is just running out at the end point.
Output format:
The output is only 1 lines, 1 integers, indicating the maximum score that xiaoming can get.
Input and Output Sample input example # #:
9 56 10 14 2 8 8 18 5 171 3 1 2 1
Sample # # of output:
73
Description
1s per test point
Xiaoming uses the creeping card sequence for 1,1,3,1,2, and gets the score of 6+10+14+8+18+17=73. Note that since the starting point is 1, the score of the 1th lattice is automatically obtained by 6.
There is 1≤n≤30,1≤m≤12 for 30% of the data.
For 50% of the data there are 1≤n≤120,1≤m≤50, and 4 kinds of crawling cards, each card will not exceed 20 number of sheets.
For 100% of the data is 1≤n≤350,1≤m≤120, and 4 kinds of crawling cards, each card will not exceed the number of 40;0≤ai≤100,1≤i≤n;1≤bi≤4,1≤i≤m.
#include <cstdio>#include<iostream>using namespacestd;Const intn= +;inta[n*Ten],b[5];intF[n][n][n][n];intn,m;intMain () {scanf ("%d%d",&n,&m); for(intI=1; i<=n;i++) scanf ("%d",&A[i]); for(intI=1, x;i<=m;i++) scanf ("%d", &x), b[x]++; for(intI=1; i<=b[1]+1; i++) for(intj=1; j<=b[2]+1; j + +) for(intk=1; k<=b[3]+1; k++) for(intL=1; l<=b[4]+1; l++) F[i][j][k][l]=max (Max (f[i-1][j][k][l],f[i][j-1][k][l]), Max (f[i][j][k-1][l],f[i][j][k][l-1])) +a[1+ (I-1)+2* (J-1)+3* (K-1)+4* (L-1)]; printf ("%d\n", f[b[1]+1][b[2]+1][b[3]+1][b[4]+1]); return 0; }
codevs1068 Tortoise Chess = = Rokua P1541 Turtle chess