1. Title Description
The polygon game is probably like this: look at the following picture:
There is a polygon, the node is a number, the edge is an operator, here only consider the "+" and "*" two, the number of two points and the operator between them to calculate the number of results after the operation of the result of a new node, so that the last only a number, we need to be able to calculate the maximum number.
2. Code
#include <stdio.h>#include <iostream>using namespace STD;intMChar*op;voidMinmax (intNintIintSintJint& Minf,int& MAXF);intPolymax (intn);intMain () {intNcout<<"Please enter number of numbers:";Cin>> N; m =New int**[n +1]; for(inti =0; I <= N; i++) M[i] =New int*[n +1]; for(inti =0; I <= N; i++) for(intj =0; J <= N; J + +) M[i][j] =New int[2];//Third dimensions 0 and 1 indicate minimum and maximum valuesOP =New Char[n];//input loop expression, one of the last inputs must be guaranteed to be an operator cout<<"Please enter an expression:"; for(inti =1; i<n; i++) {Cin>> m[i][1][0]; m[i][1][1] = m[i][1][0];Cin>> Op[i +1]; }Cin>> m[n][1][0];Cin>> op[1]; m[n][1][1] = m[n][1][0];intmax = Polymax (n);cout<<"Maximum value is:"<< Max << Endl;return 0;}//I,j the maximum and minimum values for the expression betweenvoidMinmax (intNintIintSintJint& Minf,int& MAXF) {//Set up an array to store AC,AD,BC,BD inte[5];intA, B, C, D, R; A = m[i][s][0]; b = m[i][s][1];//If n elements are exceeded, return to other locations of the ringR = (i + S-1)% n +1; c = m[r][j-s][0]; D = m[r][j-s][1];if(Op[r] = =' + ') {Minf = a + C; MAXF = B + D; }Else{//Seek maximum and minimum valuese[1] = A*c; e[2] = A*d; e[3] = B*c; e[4] = B*d; Minf = e[1]; MAXF = e[1]; for(intR =2; r<5; r++) {if(Minf>e[r]) Minf = E[r];if(Maxf<e[r]) MAXF = E[r]; } }}//Find the maximum and minimum values for the expressions between 1...NintPolymax (intN) {intMinf, MAXF;//via recursive ball minf,maxf and m[i][j][0] and m[i][j][1] for(intj =2; J <= N; J + +) for(inti =1; I <= N; i++) {//Set the maximum and minimum valuesm[i][j][0] = -2147483647; m[i][j][0] =2147483648; for(ints =1; s<j; s++) {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; } }//through different broken chain methods, the maximum value of all the maximum values inttemp = m[1][n][1]; for(inti =2; I <= N; i++)if(temp<m[i][n][1]) temp = m[i][n][1];returntemp;}
Result of Operation:
6480 = 6* (2+8) *9*12
Motion Rules-Polygon games