Test instructions:Alice and Bob play a game, there are two positive integer numbers with a length of n, each of them can only be taken from one of the sequences, and one of the two ends is selected. They all want to get the sum of the numbers as big as possible,
And they are smart enough to choose the optimal strategy every time. Alice chose first, and asked what the sum of the numbers Alice got was?
Analysis: A very obvious game problem, but with the memory of the search to solve, with D[LA][RA][LB][RB] recorded in A is only the interval of la~ra,b only left lb~rb time, Alice can get the maximum value,
So I should be able to get Bob to take the minimum of the maximum value to satisfy this problem, when Alice in the selection, she should choose Bob after the largest selection. We can do it with Sum's current sum, which is Sum-bob's choice,
The largest, can be used to solve the memory.
The code is as follows:
#include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream > #include <cstring> #include <set> #include <queue> #include <algorithm> #include <vector > #include <map> #include <cctype>using namespace std; typedef long Long Ll;typedef pair<int, int> p;c onst int inf = 0x3f3f3f3f;const double inf = 0x3f3f3f3f3f3f3f;const double EPS = 1e-8;const int maxn = 1e6 + 5;const int m OD = 1e9 + 7;const int dr[] = {0, 0,-1, 1};const int dc[] = {-1, 1, 0, 0};int N, m;inline bool is_in (int r, int c) {RE Turn r >= 0 && r < n && C >= 0 && C < m;} int a[25], b[25];int d[25][25][25][25];int dfs (int la, int ra, int lb, int rb, int sum) {if (La > ra && lb &G T RB) return 0; int &cnt = D[LA][RA][LB][RB]; if (CNT) return CNT; int Mmax = 0; if (La <= ra) Mmax = max (Mmax, Sum-min (Dfs (la+1, RA, LB, RB, Sum-a[la]), Dfs (LA, ra-1, LB, RB, Sum-a[ra]))); if (lb <= rb) Mmax = Max (Mmax, Sum-min (Dfs (LA, RA, lb+1, RB, sum-b[lb]), DFS (LA, RA, LB, rb-1, SUM-B[RB])); return cnt = Mmax;} int main () {int sum; int T; Cin >> T; while (t--) {sum = 0; scanf ("%d", &n); memset (d, 0, sizeof (d)); for (int i = 1; I <= n; ++i) scanf ("%d", &a[i]), sum + = a[i]; for (int i = 1; I <= n; ++i) scanf ("%d", &b[i]), sum + = b[i]; cout << DFS (1, n, 1, N, sum) << Endl; } return 0;}
HDU 4597 Play Game (DP, Memory search, game)