help_chenxiqing
查看原帖
help_chenxiqing
1114484
chenxiqing楼主2023/12/28 21:08
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
string s;
const int mx=210;
int l,k,a[mx],dp[mx][10][mx];
int main(){
	cin>>l>>k>>s;
	for (int i=0;i<=l-1;i++) a[i]=s[l-i-1]-'0';
	for (int i=0;i<=l-1;i++)
		for (int j=0;j<=i;j++) dp[i][0][j]=a[j];
	for (int i=1;i<=l-1;i++) 
	for (int j=0;j<=i-1;j++)
	for (int s=1;s<=min(j+1,(int)k);s++){
		int sum[mx],mul[mx];
		for (int p=0;p<=mx-1;p++) sum[p]=0,mul[p]=0;
		for (int p=j+1;p<=i;p++) sum[p-j-1]=a[p];
		int l1=mx-1,l2=mx-1,l3=mx-1;
		while (dp[i][s][l1]==0 && l1>=1 ) l1--;
		while (dp[j][s-1][l2]==0 && l2>=1 ) l2--;
		while (sum[l3]==0 && l3>=1) l3--;
		for (int p=0;p<=l2+1;p++)
			for (int u=0;u<=l3+1;u++)
			mul[p+u]+=dp[j][s-1][p]*sum[u];
		for (int p=0;p<=mx-1;p++){
			int x=mul[p];
			mul[p]%=10;
			mul[p+1]+=x/10;
		}
		int p=mx-1;
		bool bb=false;
		while (p>=0){
			if (dp[i][s][p]<mul[p]){
				bb=true;
				break;
			}
			else if (dp[i][s][p]>mul[p]) break;
			p--;
		}
		if (bb)	for (p=0;p<=mx-1;p++) dp[i][s][p]=mul[p];
	}
	int p=mx-1;
	while (dp[l-1][k][p]==0 && p>=0) p--;
	for (;p>=0;p--) cout<<dp[l-1][k][p];
	return 0;
}

https://www.luogu.com.cn/record/141261511 #在线等

急急急

!!!!!

2023/12/28 21:08
加载中...