-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp1018
41 lines (41 loc) · 862 Bytes
/
p1018
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include<iostream>
using namespace std;
long long dp[45][60];
string str;
int n,k;
long long integer[40];
long long cut(int left,int right)
{
int i;
long long product=0;
long long d=1;
for(i=right;i>=left;i--)
{
product+=integer[i]*d;
d*=10;
}
return product;
}
int main()
{
int i;
int a,b;
scanf("%d%d",&n,&k);
cin>>str;
for(i=1;i<=n;i++)
integer[i]=str[i-1]-'0';
for(i=1;i<=n;i++)
dp[i][0]=cut(1,i);
for(i=2;i<=n;i++)
{
for(a=1;a<=min(i-1,k);a++)
{
for(b=a;b<i;b++)
{
dp[i][a]=max(dp[i][a],dp[b][a-1]*cut(b+1,i));
}
}
}
cout<<dp[n][k]<<endl;
return 0;
}