NOIP2010 Raise Group Tortoise Chess-silvern

Source: Internet
Author: User

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 are 1≤n≤350,1≤m≤120, and 4 kinds of crawling cards, each card will not exceed the number ofcards 0≤ai≤100,1≤i≤n;1≤bi≤4,1≤i≤m.

Dynamic programming can be solved

Five quantities required for planning: The number of four cards used respectively, the point at which the current

The current location can be represented by the number of cards used, so the actual only four

1 /*NOIP2010 raise Group Tortoise chess Silvern*/2#include <iostream>3#include <cstdio>4#include <algorithm>5#include <cmath>6 using namespacestd;7 intf[ -][ -][ -][ -];8 ints[ -];//score9 intp[5];//Number of CardsTen intM,n; One intMain () { Ascanf"%d%d",&n,&m); -     inti,j,x; -      for(i=1; i<=n;i++) scanf ("%d",&s[i]); the      for(j=1; j<=m;j++) {//calculate the number of cards -scanf"%d",&x); -p[x]++; -     } +     intk,h; -     //enumerate the number of cards used, note that you can use the card +      for(i=0; i<=p[1];i++) A        for(j=0; j<=p[2];j++) at          for(k=0; k<=p[3];k++) -            for(h=0; h<=p[4];h++){ -               intdis=i+2*j+3*k+4*h+1; -               if(i>0&& f[i-1][J][K][H]&GT;F[I][J][K][H]) f[i][j][k][h]=f[i-1][j][k][h]; -               if(j>0&& f[i][j-1][K][H]&GT;F[I][J][K][H]) f[i][j][k][h]=f[i][j-1][k][h]; -               if(k>0&& f[i][j][k-1][H]&GT;F[I][J][K][H]) f[i][j][k][h]=f[i][j][k-1][h]; in               if(h>0&& f[i][j][k][h-1]&GT;F[I][J][K][H]) f[i][j][k][h]=f[i][j][k][h-1]; -f[i][j][k][h]+=S[dis]; to           }     +printf"%d", f[p[1]][p[2]][p[3]][p[4]]);//data to ensure all cards run out to the end -     return 0; the}

NOIP2010 Raise Group Tortoise Chess-silvern

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.