NOIP201006 Turtle Chess

Source: Internet
Author: User
Tags ming

Question 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?

Input
Enter two numbers in each line separated by a space.
The 1th row 2 positive integers n and M, respectively, representing the number of checkerboard squares and creeping cards.
Line 2nd 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 to ensure that the end point is just running out of M crawl card, that is N?1=∑MIB1.
Output
The output is only 1 lines, 1 integers, indicating the maximum score that xiaoming can get.
Input example
"Input Sample 1"
9 5
6 10 14 2 8 8 18 5 17
1 3 1) 2 1

"Input Sample 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 example
"Output Example 1"
73
"Output Example 2"
455
Other Notes
"Input and Output Sample 1 description" Xiao Ming using the crawling card sequence for 1,1,3,1,2, the score is 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.

The "Data range" 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. Input data guarantees n?1=∑mib1.

Dynamic planning.

1#include <iostream>2 3 using namespacestd;4 Long Longa[355],f[ A][ A][ A][ A]={0};5 intRead ()//Enter a template6 {7     intx=0, f=1;8     CharCh=GetChar ();9      while(ch<'0'|| Ch>'9')Ten     { One         if(ch=='-') f=-1; ACh=GetChar (); -     } -      while(ch>='0'&&ch<='9') the     { -x=x*Ten+ch-'0'; -Ch=GetChar (); -     } +     returnx*F; - }  + intMain () A { at     intn,m,b1=0, b2=0, b3=0, b4=0; -N=read (); m=read (); -      for(intI=1; i<=n;i++) a[i]=read (); -      for(intI=1; i<=m;i++) -     { -         inttemp; intemp=read (); -         if(temp==1) b1++; to         Else if(temp==2) b2++; +         Else if(temp==3) b3++; -         Elseb4++; the     } *f[0][0][0][0]=a[1]; $      for(intx4=0; x4<=b4;x4++)Panax Notoginseng     { -          for(intx3=0; x3<=b3;x3++) the         { +              for(intX2=0; x2<=b2;x2++) A             { the                  for(intx1=0; x1<=b1;x1++) +                 { -                     intA=0, b=0, c=0, d=0; $                     if(x1>0) a=f[x1-1][x2][x3][x4]+a[x1+2*x2+3*x3+4*x4+1]; $                     if(x2>0) b=f[x1][x2-1][x3][x4]+a[x1+2*x2+3*x3+4*x4+1]; -                     if(x3>0) c=f[x1][x2][x3-1][x4]+a[x1+2*x2+3*x3+4*x4+1]; -                     if(x4>0) d=f[x1][x2][x3][x4-1]+a[x1+2*x2+3*x3+4*x4+1]; the                     if(x1==0&& x2==0&& x3==0&& x4==0)Continue; -                     Elsef[x1][x2][x3][x4]=Max ( A, b), Max (c,d));Wuyi                 } the             } -         } Wu     } -printf"%d", F[b1][b2][b3][b4]); AboutSystem"Pause"); $     return 0; -}
NOIP201006 Turtle Chess

NOIP201006 Turtle 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.