1. Problem description: Given the polygon of N vertices, each vertex is labeled with an integer and each edge is marked with a plus or a multiplication sign, and N edges are numbered 1 ~ clockwise ~ N. Returns a polygon with N = four vertices. Game rules: (1) first, remove an edge. (2) perform the following operations: select an edge E, which has two adjacent vertices, which may be V1 and V2. Calculate the Integers of vertices V1 and V2 according to the operator number (+ or ×) labeled on E to obtain an integer. Use this integer to mark a new vertex, this vertex replaces V1 and V2. This operation continues until no edge exists, that is, only one vertex is left. The integer of This vertex is called the Score of this game ). 2. Problem analysis: the problem can be solved by the optimal sub-structure in dynamic planning. Set the clockwise sequence of the vertices and edges of the given polygon to op [1], v [1], op [2], v [2], op [3],…, Op [n], v [n] Where op [I] represents the operator corresponding to the I-th edge, and v [I] represents the value on the I-th vertex, I = 1 ~ N. In the given polygon, from vertex I (1 <= I <= n), the clockwise link p (I, j) with a length of j (j vertices in the chain) can be expressed as v [I], op [I + 1],…, V [I + J-1], if the last merge operation of this chain occurs at op [I + s] (1 <= s <= J-1 ), the link can be divided into two sub-chains p (I, s) and p (I + s, j-s) at op [I + s ). For www.2cto.com, m [I, j, 0] is the minimum value of chain p (I, j) Merge, while m [I, j, 1] is the maximum value. If the optimal combination is at op [I + s], the maximum and minimum values of p (I, j) Sub-chains with a length less than j are calculated. That is, a = m [I, s, 0] B = m [I, s, 1] c = m [I, s, 0] d = m [I, s, 1] (1) When op [I + s] = '+' m [I, j, 0] = a + c; m [I, j, 1] = B + d (2) When op [I + s] = '*', www.2cto.com m [I, j, 0] = min {ac, ad, bc, bd}; m [I, j, 1] = max {ac, ad, bc, bd} due to the optimum disconnection position s has 1 <= s <= J-1 In the J-1. The initial boundary value is m [I, 1, 0] = v [I] 1 <= I <= n m [I, 1, 1] = v [I] 1 <= I <= n is closed due to the variable form. In the above calculation, When I + s> n, vertex I + s is actually numbered (I + s) modn. The m [I, n, 1] calculated based on the above recursive formula is the maximum score obtained after the game deletes the I-th edge for the first time. The specific algorithm code is as follows: [cpp] // 3d6 polygon game # include "stdafx. h "# include <iostream> using namespace std; # define NMAX 100 int N, m [NMAX + 1] [NMAX + 1] [2], v [NMAX + 1]; char op [NMAX + 1]; void MinMax (int n, int I, int s, int j, int & minf, int & maxf); int PloyMax (int n, int & p); int main () {int p; cout <"Enter the number of polygon vertices:" <endl; cin> N; for (int I = 1; I <= N; I ++) {cout <"Enter the polygon vertex" <I <"value:" <endl; cin> v [I]; m [I] [1] [0] = v [I]; m [I] [1] [1] = v [I]; cout <"Enter the polygon edge" <I <"OPERATOR:" <endl; cin> op [I];} cout <"polygon game first deletes vertex" <p <", and the result is:" <PloyMax (N, p) <endl; return 0 ;} void MinMax (int n, int I, int s, int j, int & minf, int & maxf) {int e [5]; int a = m [I] [s] [0], B = m [I] [s] [1]; int r = (I + s-1) % n + 1; // actual vertex number of the polygon int c = m [r] [j-s] [0], d = m [r] [j-s] [1]; if (op [r-1] = '+') {minf = a + c; maxf = B + d;} else {e [1] = a * c; e [2] = a * d; e [3] = B * c; e [4] = d * B; minf = e [1]; maxf = e [1]; for (int r = 2; r <N; r ++) {if (minf> e [r]) minf = e [r]; if (maxf <e [r]) maxf = e [r] ;}} int PloyMax (int n, int & p) {int minf, maxf; for (int j = 2; j <= n; j ++) // The length of the iteration Chain {for (int I = 1; I <= n; I ++) // Delete the I-th edge for the first iteration {for (int s = 1; s <j; s ++) // iteration disconnection position {MinMax (n, I, s, j, minf, maxf); if (m [I] [j] [0]> minf) m [I] [j] [0] = minf; if (m [I] [j] [1] <maxf) m [I] [j] [1] = maxf ;}}} int temp = m [1] [n] [1]; p = 1; for (int I = 2; I <= n; I ++) {if (temp <m [I] [n] [1]) {temp = m [I] [n] [1]; p = I ;}} return temp ;} the program running result is as follows: