# 1068 Tortoise Chess

Source: Internet
Author: User

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 Input 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 Output Description

Output one line of integers

Sample input 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 Sample Output

455

Data range and Tips Data Size & Hint

"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=σm

I b

1

Use a, B, C, d respectively to indicate the number of crawl cards 1, 2, 3, 4. and recursively to find the score before each step and the position after the step is the maximum total score.

The AC code is attached:

`1#include <iostream>2#include <cstring>3#include <cmath>4 using namespacestd;5 6 intf[ A][ A][ A][ A];7 ints[351];8 9 intMain () {Ten     intn,m,x; OneCin>>n>>m; A     intA=0, b=0, c=0, d=0;//used to represent the number of 1,2,3,4 -      for(intI=0; i<n;i++){ -Cin>>S[i]; the     } -      for(intI=0; i<m;i++) {//statistics of crawling cards -Cin>>x; -         if(x==1) +a++; -         if(x==2) +b++; A         if(x==3) atC++; -         if(x==4) -d++; -     } -      -      for(intI=0; i<=a;i++){ in          for(intj=0; j<=b;j++){ -              for(intk=0; k<=c;k++){ to                  for(intL=0; l<=d;l++) {//calculate the size before each step, plus the size of the position after the walk +                     if(i!=0) -F[i][j][k][l]=max (f[i][j][k][l],f[i-1][j][k][l]); the                     if(j!=0) *F[i][j][k][l]=max (f[i][j][k][l],f[i][j-1][k][l]); \$                     if(k!=0)Panax NotoginsengF[i][j][k][l]=max (f[i][j][k][l],f[i][j][k-1][l]); -                     if(l!=0) theF[i][j][k][l]=max (f[i][j][k][l],f[i][j][k][l-1]); +f[i][j][k][l]+=s[i+j*2+k*3+l*4]; A                 } the             } +         } -     } \$cout<<f[a][b][c][d]<<Endl; \$     return 0; -}`

1068 Tortoise Chess

Related Keywords:

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.