11121
Using the idea of dynamic planning, thought for a whole afternoon, did not expect to finally make a 5-layer cycle of dynamic planning. Fortunately, the topic of AC, and then see the answer on the Internet, using the DP interval dynamic programming algorithm, today do not study, some tired. Here's my algorithm.
#include <string>#include<sstream>#include<iostream>#include<string.h>#include<stdio.h>using namespacestd;#defineNUM 20Long LongAtoll (Const Char*p) {StringStream strvalue; strvalue<<p; Long Longvalue; strvalue>>value; returnvalue;}intMain () {intcount; scanf ("%d", &count); while(count--) { intI,j,k,l,m,n; Long LongMm[num][num][num]; CharNum[num]; CharTemp[num]; scanf ("%s", num); N=strlen (num); scanf ("%d", &m); for(k =0; K < M; k++) { for(i =0; I < n; i++) { for(j = i + K; j < N; j + +) { if(k = =0) {strncpy (temp, num+i, j-i+1); Temp[j-i+1] =' /'; MM[I][J][K]=Atoll (temp); } Else { Long Longres =-1; for(L =0; L < J-i; l++) { intO, k1=0, k2=0; for(o =0; o < L +1&& O < K; o++) {K1=o; K2= K-1-K1; Long LongTRes = mm[i][i+l][k1] * mm[i+l+1][J][K2]; Res= res > TRes?Res:tres; }} Mm[i][j][k]=Res; } }}} cout<< mm[0][n-1][m-1] <<Endl; } return 0;}
DP interval algorithm
#include <iostream>#include<cstdio>#include<string>#include<cmath>#include<algorithm>typedefLong LongLl;typedefLong Longarray[ A]; Array ob;ll n,m,res,reco,rec,cur,maxs,temp;using namespaceStd;ll Pow_dfs (ll i) {ll ress=1; for(LL j=1; j<=i;j++) {ress*=Ten; } returnress;} ll Maxmin (ll A,ll b) {returnA>b?a:b;}voidDFS (ll pos,ll rec,ll now) {if(rec==m-1) {Ob[rec]=Now ; Cur=1; for(intI=0; i<m;i++) {cur*=Ob[i]; } maxs=maxmin (CUR,MAXS); return ; } if(pos>=reco)return ; DFS (POS+1, Rec,now); OB[REC]=now/pow_dfs (reco-POS); now=now%pow_dfs (reco-POS); DFS (POS+1, rec+1, now);}intMain () {ll T; //freopen ("D://imput.txt "," R ", stdin);scanf"%lld",&T); while(t--) {Reco=1; maxs=0; scanf ("%lld%lld",&n,&m); Temp=N; while(temp/Ten) {Temp=temp/Ten; Reco++; } DFS (1,0, N); printf ("%lld", MAXS); if(t!=0) printf ("\ n"); } return 0;}