Luo gu 1018 product max

Source: Internet
Author: User

Title 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.

Input/output format

Input format:

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 format:

The result is displayed on the screen, and the maximum product (a natural number) should be output relative to the input.

Input/Output sample

Input Sample # #:

4  21231

Sample # # of output:

62
Description

The second problem of NOIp2000 raising group

Thinking of solving problems

DP,F[I,J] Indicates the maximum product of J multiplication Sign in the number of pre-I

F[i,j]:=max (F[k,j-1]*a) (K=1 to I-1)

1  Programmult;2 uses math;3 var4f:array[0.. +,0..6] ofQword;5 N,k,x,i,j,l,a,c:longint;6 s,s1:string;7 begin8 readln (n,x);9 Readln (s);Tenl:=length (s); One      fori:=1  toL Do A     begin -S1:=copy (s),1, i); - Val (s1,a,c); theF[i,0]:=A; -     End; -      fori:=2  toL Do//number of first few -          forj:=1  toI-1  Do +              fork:=1  toMin (i1, x) Do -             begin +S1:=copy (s,j+1, I-j); A Val (s1,a,c); at                 iff[i,k]<f[j,k-1]*a Thenf[i,k]:=f[j,k-1]*A; -             End; - Writeln (f[n,x]); - End.

Luo gu 1018 product max

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.