import java.util.Scanner;
public class Main {
static int[] arr = new int[41];
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int K = sc.nextInt();
String s = sc.next();
for(int i = 0;i<N;i++){
arr[i] = Integer.valueOf(s.charAt(i)+"");
}
int[][] dp = new int[N+1][K+1];
int temp = 0;
for(int i = 0;i < N;i++){
temp = temp*10 + arr[i];
dp[i+1][0] = temp;
}
for(int i = 1;i <= N;i++){
for(int j = 1;j <= K;j++){
for(int u = 1;u < i;u++){
dp[i][j] = Math.max(dp[i][j],dp[u][j-1]*(dp[i][0] - (dp[u][0]*(int)Math.pow(10,i-u))));
}
}
}
System.out.println(dp[N][K]);
}
}
java 蓝桥杯 最大乘积(DP)
最新推荐文章于 2022-11-03 15:17:35 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)