Title: Portal
The title describes this was a very simple problem, just like previous one. You is given a postive integer n, and you need to divide this integer into m pieces. Then multiply the M pieces together. There is many a-do. But Shadow95 want to know the maximum result of you can get. Input first line is a postive integer t, means there is t-test case S.following T lines, each line there is the integer n, M. (0<=n<=10^18, 0 < m < log10 (n)) output the Maximu M result you can get. Example input
1123 2
Sample output
36
Tip You can divide "123" to "a" and "3". Then the maximum result is 12*3=36. Test instructions is very simple, but I was a slag, DP in the game never had a, decisive or look at the problem, but also only this type, other types of interval DP decisive or not, decisive can not extrapolate ah. The code is as follows:
#include <iostream>#include<algorithm>#include<stdio.h>#include<string.h>typedefLong Longll;using namespacestd;#defineMoD 1000000007intm,l;Chars[ A];//local variables are completely different from global variables for string lengthsll a[ -][ -],dp[ -][ -];intMain () {intT; scanf ("%d",&T); while(t--) {scanf ("%s", s+1); scanf ("%d",&m); L=strlen (s+1); Memset (A,0,sizeof(a)); if(m==1|| m==0) {printf ("%s\n", s+1); Continue; } for(intI=1; i<=l;i++) { for(intj=i;j<=l;j++) {A[i][j]=a[i][j-1]*Ten+ (s[j]-'0'); }} memset (DP,0,sizeof(DP)); for(intI=0; i<=l;i++) dp[i][1]=a[1][i]; for(intj=2; j<=m;j++) { for(inti=j;i<=l;i++) { for(intk=1; k<i;k++) {Dp[i][j]=max (dp[i][j],dp[k][j-1]*a[k+1][i]); }}} printf ("%lld\n", Dp[l][m]); } return 0;}
Sdut3146:integer Division 2 (integer divide interval dp)