标签:
4 2
1231
62
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> using namespace std; const int maxn = 300; int n,m,u,j; long long int num,sum[maxn][maxn],dp[maxn][maxn]; int main(){ memset(dp,0,sizeof(dp)); cin>>n>>m>>num; for(int i = 1;i <= n;i++){ sum[i][i] = num % 10; num /= 10; } u = 10; for(int l = 2;l <= n;l++){ for(int i = 1;i <= n - l + 1;i++){ j = i + l - 1; sum[i][j] = sum[i][j-1] + u * sum[j][j]; } u *= 10; } for(int i = 1;i <= n;i++) dp[0][i] = sum[1][i]; for(int i = 1;i <= m;i++){ for(int j = i+1;j <= n;j++){ for(int k = i;k < j;k++){ dp[i][j] = max(dp[i][j],dp[i-1][k] * sum[k+1][j]); } } } cout<<dp[m][n]; return 0; }
标签:
原文地址:http://www.cnblogs.com/hyfer/p/5811964.html