F. largest product
Title Description
This year is the International Mathematical Union to determine the "2000-- World Mathematics", also coincides with the 90th anniversary of a famous mathematician, Mr. Hua birthday. Mr. Hua's hometown Jintan, math quiz organized activity of a spectacular, one of your good friend XZ also had the honor to participate. Activity, the host to all the players participating in a such a Title: with a length of N strings of numbers, the player requires the use of the K multiplication sign it into K + 1 parts, to find a points, K + 1 such that the product of these portions is maximized. Meanwhile, in order to help the player can correctly understanding the problem, a moderator is also cited in the following examples: a string of numbers: 312, when N = 3, K = 1 there will be the following two points Method: 1) 3 12 = 362) 31 2 = 62 in this case, the result is in line with requirements of the subject: 31 * 2 = 62. Now, you help your friends XZ design a program to obtain the correct answer.
Input Format
There are a first line of two natural numbers N, K (6≤N≤40,1≤K≤6)
The second line is a numeric string of length N.
Output Format
The product obtained maximum output (a natural number).
Sample
Sample input
4 2
1231
Sample Output
62
. 1 #include <the iostream> 2 #include <CString> . 3 #include <cstdio> . 4 #include <Stack> . 5 the using namespace STD; . 6 unsigned Long Long n-, / * K th multiplication, k + 1 partial * / DP [ 50 ] [ 10 ], A [ 41 is ] [ 41 is ] / * before i j bits into segments * / , Ink; . 7 int K6; . 8 char in [ 51 is ]; . 9 int main () 10 { . 11 cin>>n>>k6; 12 k6++; 13 cin>>in+1; 14 for(int i=1;i<=n;i++) 15 { 16 ink=0; 17 for(int j=i;j<=n;j++) 18 { 19 ink=ink*10+in[j]-'0'; 20 A[i][j]=ink; 21 } 22 } 23 dp[0][0]=1; 24 for(int i=1;i<=n;i++)/*dp[i][j]-->前i位分成j段*/ 25 { 26 int ki=min(i,k6); 27 for(int j=1;j<=ki;j++) 28 { 29 for(int k=1;k<=i;k++) 30 { 31 if(dp[k-1][j-1]*A[k][i]>dp[i][j]) 32 { 33 dp[i][j]=dp[k-1][j-1]*A[k][i]; 34 } 35 } 36 } 37 } 38 cout<<dp[n][k6]; 39 }