#include <cstdio>
#include <cstdlib>
using namespace std;
#define max(a,b) a>b?a:b
long long f[49][9],a[49];
int main() {
int n,m;
char ch;
scanf("%d%d",&n,&m);
scanf("%c",&ch);
for (int i=1;i<=n;i++) {
scanf("%c",&ch);
a[i]=ch-48;
}
for (int i=1;i<=n;i++) f[i][0]=f[i-1][0]*10+a[i];
for (int i=n;i>=1;i--) {
for (int j=1;j<n-i+1;j++) a[i]*=10;
a[i]+=a[i+1];
}
for (int i=1;i<=m;i++)
for (int j=i+1;j<=n;j++)
for (int k=i;k<=j-1;k++) {
int t=(a[k+1]-a[j+1]);
for (int w=1;w<n-j+1;w++) t/=10;
f[j][i]=max(f[j][i],f[k][i-1]*t);
}
printf("%lld\n",f[n][m]);
return 0;
}
有没有大神帮忙看下哪里有问题
#include <cstdlib>
using namespace std;
#define max(a,b) a>b?a:b
long long f[49][9],a[49];
int main() {
int n,m;
char ch;
scanf("%d%d",&n,&m);
scanf("%c",&ch);
for (int i=1;i<=n;i++) {
scanf("%c",&ch);
a[i]=ch-48;
}
for (int i=1;i<=n;i++) f[i][0]=f[i-1][0]*10+a[i];
for (int i=n;i>=1;i--) {
for (int j=1;j<n-i+1;j++) a[i]*=10;
a[i]+=a[i+1];
}
for (int i=1;i<=m;i++)
for (int j=i+1;j<=n;j++)
for (int k=i;k<=j-1;k++) {
int t=(a[k+1]-a[j+1]);
for (int w=1;w<n-j+1;w++) t/=10;
f[j][i]=max(f[j][i],f[k][i-1]*t);
}
printf("%lld\n",f[n][m]);
return 0;
}
有没有大神帮忙看下哪里有问题