TYVJ 1402 Tortoise-Chess DP

Source: Internet
Author: User

P1402[NOIP2010] Tortoise Chess Time: 1000ms/Space: 131072kib/java class name: main background

NOIP2010 to improve the second question of group rematch

Describe

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 Checkerboard 1th is the only
Starting point, Nth grid is the end point, 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 in Tortoise chess, divided into 4 different types (m card does not necessarily contain all 4 types
Card, see example), each type of card is labeled with 1, 2, 3, 44 digits, indicating the use of such cards
After the piece, the turtle piece will crawl forward the corresponding number of squares. In the game, players need to choose from all the crawl cards each time
A crawl card that has not been used before, controls the corresponding number of squares for the turtle to advance, and can only be used once per card.
In the game, the turtle piece automatically obtains the score of the starting point lattice, and in the subsequent crawl each arrives a lattice, obtains
The corresponding fraction of the lattice. The player's final game score is all the squares from the beginning to the end of the turtle piece.
The sum of the scores.
Obviously, the use of different crawling cards in the order will make the final game score different, Xiaoming wants to find a card
The order of the tablets makes the final game the most points.
Now, tell the score of each lattice on the board and all the crawling cards, and you can tell Xiaoming that he can get
How many points?

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, a1,a2,......, An, where AI represents the score on the first lattice of the chessboard.
Line 3rd m integer, B1,b2, ..., BM, represents the number on the M-card crawl card.
Input data guaranteed to reach the end point just ran out of M-card crawling

Output format

The output is only 1 lines, 1 integers, indicating the maximum score that xiaoming can get.

Test Sample 1 input
Input Example 1
7 {
6 10 14 2 8 8 18 5 17
1 3 1) 2 1

Input Example 2
13 8
4 96 10 64 55 13 94 53 5 24 89 8 30
1 1 1 1 1 2 4 1
Output
Output Example 1
73

Output Example 2
455
Note

"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.

#include <iostream>#include<cstdio>#include<cmath>#include<string>#include<queue>#include<algorithm>#include<stack>#include<cstring>#include<vector>#include<list>#include<Set>#include<map>using namespacestd;#definell __int64#defineESP 0.00000000001Const intn=1e3+Ten, m=1e6+Ten, inf=1e9+Ten, mod=1000000007;intA[n];intdp[ -][ -][ -][ -];intflag[5];voidinit () {memset (flag,0,sizeof(flag)); Memset (DP,0,sizeof(DP));}intMain () {intx,y,z,i,t,j,k;  while(~SCANF ("%d%d",&x,&y)) {init ();  for(i=1; i<=x;i++) scanf ("%d",&A[i]);  for(i=1; i<=y;i++) {scanf ("%d",&z); FLAG[Z]++; }         for(i=0; i<=flag[4];i++)             for(t=0; t<=flag[3];t++)                 for(j=0; j<=flag[2];j++)                     for(k=0; k<=flag[1];k++)                    {                        if(i>0) Dp[i][t][j][k]=max (dp[i][t][j][k],dp[i-1][t][j][k]); if(t>0) Dp[i][t][j][k]=max (dp[i][t][j][k],dp[i][t-1][j][k]); if(j>0) Dp[i][t][j][k]=max (dp[i][t][j][k],dp[i][t][j-1][k]); if(k>0) Dp[i][t][j][k]=max (dp[i][t][j][k],dp[i][t][j][k-1]); DP[I][T][J][K]+=a[i*4+t*3+j*2+k+1]; } printf ("%d\n", dp[flag[4]][flag[3]][flag[2]][flag[1]]); }    return 0;}

TYVJ 1402 Tortoise-Chess DP

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.