2010 Tortoise Chess

Source: Internet
Author: User

Turtle Chess Title Description

Xiao Ming's birthday, his father gave him a pair of turtle chess as a gift. 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.

...... 1 2 3 4 5 ... N the M-card crawl card, divided into 4 different types (m card does not necessarily contain all 4 types of cards, see sample), each type of card is marked 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?

Enter a description

The input is separated by a space between two numbers in each row. The 1th row 2 positive integers n and M, respectively, representing the number of checkerboard squares and creeping cards. Row 2nd n non-negative integers, a1a2......an

, where AI represents the score on the first lattice of the chessboard. Line 3rd m Integer, B1B2......BM

That represents the number on the M-card crawl card. Input data guaranteed to reach the end point just ran out of M-card crawling cards, namely N-1=∑ (1->m) bi

Output Description

Outputs an integer line.

Sample Input

13 8

4 96 10 64 55 13 94 53 5 24 89 8 30

1 1 1 1 1 2 4 1

Sample Output

455

data range and tips

"Data Range"

There is 1≤n≤30,1≤m≤12 for 30% of the data.

For 50% of the data is 1≤n≤120,1≤m≤50, and 4 kinds of crawling cards, each card will not exceed the number of

Over 20.

For 100% of the data is 1≤n≤350,1≤m≤120, and 4 kinds of crawling cards, each card number of cards will not

More than 40;0≤ai≤100,1≤i≤n;1≤bi≤4,1≤i≤m. Input data Assurance n−1=σ (1->m) bi

//four parameters, indicating the usage of each card;//F[i][j][k][v]=max (F[i-1][j][k][v],f[i][j-1][k][v],f[i][j][k-1][v],f[i][j][k][v-1]) +a[i+j*2+k*3+v*4];#include <cstdio>intn,m,a[352],b[5],c[5]={0},ans;intsz[ +][ +][ +][ +]={0};intMaxintAintb) {    returnA>b?a:b;}intMain () {scanf ("%d%d",&n,&m);  for(intI=0; i<n;i++) scanf ("%d", A +i);  for(intI=1; i<=m;i++) {scanf ("%d",&ans); B[ans]++;//accumulate the number of each kind of card;    }     for(intx=0; x<=b[1];x++)     for(inty=0; y<=b[2];y++)     for(intL=0; l<=b[3];l++)     for(intR=0; r<=b[4];r++){        if(x!=0) Sz[x][y][l][r]=max (sz[x][y][l][r],sz[x-1][y][l][r]); if(y!=0) Sz[x][y][l][r]=max (sz[x][y][l][r],sz[x][y-1][l][r]); if(l!=0) Sz[x][y][l][r]=max (sz[x][y][l][r],sz[x][y][l-1][r]); if(r!=0) Sz[x][y][l][r]=max (sz[x][y][l][r],sz[x][y][l][r-1]);//like the way to take the stairs to beg;sz[x][y][l][r]+=a[x+y*2+l*3+r*4]; } printf ("%d", sz[b[1]][b[2]][b[3]][b[4]]); return 0;}
View Code

2010 Tortoise Chess

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.