Bzoj1806[ioi2007]miners miner Food pairing DP

Source: Internet
Author: User

"Topic link"

DP[I][A1][A2][B1][B2] said that the first I food, the last two times of food in the mine were A1, A2,B1, B2 the same, the maximum number of coal obtained.

/* Think Thank Thunk */#include <cstdio> #include <cstring> #include <algorithm> #define REC (i, x, y) F

or (int i = x; i <= y; i++) using namespace std;

int n, dp[2][4][4][4][4];
	inline int cread () {Char ch = getchar ();
	for (; ch! = ' M ' && ch! = ' F ' && ch! = ' B '; ch = getchar ());
	if (ch = = ' M ') return 1;
	if (ch = = ' F ') return 2;
if (ch = = ' B ') return 3;
	} inline int calc (int A, int b, int c) {int res = 1;
	if (A! = 0 && A! = b && A! = c) res++;
	if (b! = 0 && B! = c) res++;
return res;
	} int main () {scanf ("%d", &n);
	Memset (DP,-1, sizeof (DP));

	Dp[0][0][0][0][0] = 0;
		Rec (i, 0, n-1) {int t = Cread ();
			Rec (A1, 0, 3) rec (A2, 0, 3) Rec (b1, 0, 3) rec (b2, 0, 3) {if (!~dp[i & 1][A1][A2][B1][B2]) continue;
			Dp[~i & 1][a2][t][b1][b2] = Max (Dp[~i & 1][a2][t][b1][b2], Dp[i & 1][A1][A2][B1][B2] + calc (a1, A2, T)); Dp[~i & 1][a1][a2][b2][t] = Max (Dp[~i & 1][a1][a2][b2][t], Dp[i & 1][A1][A2][B1][B2] + calc (b1, B2, T));
	}} int ans = 0;
	Rec (A1, 0, 3) rec (A2, 0, 3) Rec (b1, 0, 3) rec (b2, 0, 3) ans = max (ans, dp[n & 1][a1][a2][b1][b2]);
	printf ("%d\n", ans);
return 0;
 }


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.