http://tyvj.cn/p/1047
PS:此题可以不用高精度AC(数据水)
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ms(i,j) memset(i, j, sizeof(i));
using namespace std;
typedef long long ll;
int a[50][50];
ll f[10][50]; //设f[k][n]为前n个数k个乘号时的最大乘积
//f[k][i] = max(f[k-1][j]*a[j+1][i])
int main()
{
<span style="white-space:pre"> </span>int n,K;
<span style="white-space:pre"> </span>ll s;
<span style="white-space:pre"> </span>scanf("%d%d%lld", &n, &K, &s);
<span style="white-space:pre"> </span>int i = n;
<span style="white-space:pre"> </span>while (s!=0)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>a[i][i] = s % 10;
<span style="white-space:pre"> </span>s /= 10;
<span style="white-space:pre"> </span>i--;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>for (int i=1;i<=n;i++)
<span style="white-space:pre"> </span>for (int j=i+1;j<=n;j++)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>a[i][j] = a[i][j-1] * 10 + a[j][j];
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>ms(f,0);
<span style="white-space:pre"> </span>for (int i=1;i<=n;i++) f[0][i] = a[1][i];
<span style="white-space:pre"> </span>for (int k=1;k<=K;k++)//以乘号划分阶段
<span style="white-space:pre"> </span>for (int i=k+1;i<=n;i++)//以数字划分状态
<span style="white-space:pre"> </span>for (int j=1;j<i;j++)
<span style="white-space:pre"> </span>f[k][i] = max(f[k][i], f[k-1][j]*a[j+1][i]);
<span style="white-space:pre"> </span>printf("%d\n", f[K][n]);
return 0;
}