1017 Product Maximum
2000 Noip National League popularization Group Noip National League Improvement Group
time limit: 1 sspace limit: 128000 KBtitle level: Golden GoldTitle Description
Description
This year is the "2000--World Mathematics Year" established by the International Mathematical Union, and coincides with the 90 anniversary of the birth of our famous mathematician Mr. Hua. In Mr. Hua's hometown of Jintan, Jiangsu, organized a wonderful mathematical intelligence contest activities, a good friend of your XZ is also fortunate to participate. During the event, the host gives all the participants a title:
There is a number string of length n, requiring the player to use K multiplication sign to divide it into k+1 parts, to find a division, so that this k+1 part of the product can be the largest.
At the same time, in order to help the player to understand test instructions correctly, the moderator also gave the following example:
There is a number string: 312, when N=3,k=1 will have the following two kinds of methods:
1) 3*12=36
2) 31*2=62
At this point, the result that meets the requirements of the question is: 31*2=62
Now, please help your good friend XZ design a program to get the right answer.
Enter a description
Input Description
There are two lines of input to the program:
The first line has a total of 2 natural numbers n,k (6≤n≤40,1≤k≤6)
The second line is a number string with a length of N.
Output description
Output Description
The result is displayed on the screen, and the maximum product (a natural number) should be output relative to the input.
Sample input
Sample Input
4 2
1231
Sample output
Sample Output
62
A very typical interval DP (I heard that the data is very water DP can be too, did not try, not in this discussion, interested students can try), code on the data is water, said int64, direct longint no brain A.
Of course, the correct idea is to say:
First of all, this interval DP is very bare, no messy notes, three cycles must pay attention to order, the number of titles placed in the outermost layer, followed by the length of the enumeration, the most internal is the modification decision.
Initialize: The value of each interval (i,j) in the string is preprocessed, recorded as an array of a, initialization will dp[i,0] a[1,i] can be
Code stickers on
varF,a:Array[0.. the,0.. the] ofInt64; X,y,i,j,k,m,n,l:longint; s:string; functionMax (a,b:longint): Longint; begin ifA>b ThenExit (a)ElseExit (b);End; functionnum (x,y:longint): Int64; varI:int64; J:longint; beginI:=0; forJ:=x toY DoI:=i*Ten+ (ord (s[j))- -); Exit (i); End; beginreadln (n,k); READLN (s); L:=length (s); fori:=1 toL Do forj:=1 toL DoA[i][j]:=num (i,j); fori:=1 toL Dof[i][0]:=a[1][i]; form:=1 toK Do fori:=m+1 toL Do forJ:=m toi+1 DoF[i][m]:=max (f[i][m],f[j][m-1]*a[j+1][i]); Writeln (F[n][k]); End.
Like on the collection, Vic private qq:1064864324, add me to discuss issues together, and progress
[codevs1017] Product maximum