NOIP2010 Turtle Chess (multidimensional DP)

Source: Internet
Author: User

The test is always thinking that the first dimension is to go to the maximum value of I time, and then did not consider that this can calculate the number of each card used ....

Dp[i][j][k][l] means the first card with I, the second card with J, the third card with K, the fourth card with L-sheet maximum

#include <cstdio> #include <iostream> #define MAXN 355using namespace Std;int c[5],a[maxn],f[41][41][41][41  ];int N,m;int Main () {scanf ("%d%d", &n,&m), int x;for (int i = 1; I <= n; i++) scanf ("%d", &a[i]); for (int i = 1; I <= m; i++) {scanf ("%d", &x); c[x]++;} F[0][0][0][0] = a[1];f[1][0][0][0] = a[2];f[0][1][0][0] = a[3];f[0][0][1][0] = a[4];f[0][0][0][1] = a[5];for (int i = 0; i <= C[1]; i++) for (int j = 0; J <= C[2]; + j) for (int k = 0, K <= c[3]; k++) for (int l = 0; l <= c[4]; l++) {int w = I,x = J,y = K,z = L;if (w! = 0) W = f[i-1][j][k][l];if (x! = 0) x = f[i][j-1][k][l];if (Y! = 0) y = f[i][j][k-1][l];if (Z! = 0) z = f[i] [j] K [L-1];int t = max (W,max (X,max (y,z))); F[i][j][k][l] = t + a[1+i+2*j+3*k+4*l];} printf ("%d\n", F[c[1]][c[2]][c[3]][c[4]]);}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

NOIP2010 Turtle Chess (multidimensional 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.