[NOIP2010] Turtle chess (DP)

Source: Internet
Author: User

Transmission Door
Idea: Classic DP problem, I come to water a water, see the data range should be able to know this is a multidimensional DP, we can set F (I,J,k,L,m) I walked the first card with J, the 2nd card with K, the 3rd card with L, the 4th card with the maximum score after M. But we found that this transfer, not only the memory is not open, and the transfer time will be timed out, what to do, we found that the five number is not independent, you can know 4 for 5, so we can simply omit 1 dimensions into 4 dimensional space, it can be opened.

Code:

#include <cstdio>InlineintMaxintAintb) {returnA&GT;B?A:B;}intNm;inta[355], card[5];intf[ A][ A][ A][ A];intMain () {inti,k,j,l; scanf"%d%d",&n,&m); for(i =1; I <= N; i + +) scanf ("%d", &a[i]); for(i =1; I <=m; i + +) {scanf ("%d", &j);    card[j]++; } for(i=0; i<=card[1]; i + +) for(j=0; j<=card[2]; J + +) for(k=0; k<=card[3]; K + +) for(l=0; l<=card[4]; L + +) {intA1 = i==0?0: f[i-1][J][K][L];intA2 = j==0?0: f[i][j-1][K][L];intA3 = k==0?0: f[i][j][k-1][L];inta4 = l==0?0: f[i][j][k][l-1];intt = max (max (A1,A2), Max (A3,A4)); F[I][J][K][L] = t+a[i+2*j+3*k+4*l+1]; }printf("%d", f[card[1]][card[2]][card[3]][card[4]]);}

Copyright NOTICE: Please feel free to reprint O (∩_∩) o

[NOIP2010] Turtle 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.