20pts 求调
查看原帖
20pts 求调
1088203
Mingjunyi楼主2024/3/2 16:46
#include <bits/stdc++.h>
using namespace std;
#define For(i,a,n) for(register int i = a;i<=n;i++)
#define Dec(i,a,n) for(register int i = a;i>=n;i--)
#define CIN const int
#define il inline
#define LOG2(x) __lg(x)
#define MJY(p) freopen(p".in","r",stdin);freopen(p".out","w",stdout);
#define int __int128

int read(){
	int x = 0,w = 1;
	char ch = 0;
	while(ch < '0' || ch > '9') {
		if(ch == '-') w = -1;
		ch = getchar();
	}
	while(ch >= '0'&&ch<= '9') {
		x = x*10 + (ch - '0');
		ch = getchar();
	} 
	return x*w;
}

void write(int x){
	static int sta[35];
	int top = 0;
	do{
		sta[top++] = x%10,x = x / 10;
	}while(x);
	while(top) putchar(sta[--top] + 48);
}

CIN N = 45;
int n,k,dp[N][10],suf[N][N];
char num[N];

signed main() {

	n = read();
	k = read();
	scanf("%s",num + 1);
	For(i,1,n) For(j,i,n) suf[i][j] = suf[i][j-1]*10 + (int)num[j] - '0';
	For(i,1,n) dp[i][0] = suf[1][i]; 
	For(t,1,k) {
		For(i,t,n) {
			For(j,t,i-1) {
				dp[i][t] = max(dp[i][t],dp[j][t-1] * suf[j+1][i]);
			}
		}
	}
	write(dp[n][k]);
	
	return 0;
}

2024/3/2 16:46
加载中...