题目大意:
http://codevs.cn/problem/1017/
题解:
#include <iostream> using namespace std; char ch[45]; int n,k; long long int arr[45][7]; long long int dp[45][7]; int main() { cin >> n >> k >> ch; for(int i = 0; i < n; i++){ int tmp = 0; for(int j = i; j < n; j++){ tmp = tmp * 10 + ch[j]-‘0‘; arr[i][j] = tmp; } } //dp 开始 for(int i = 0; i < n; i++){ dp[i][0] = arr[0][i]; } for(int i = 0; i < n; i++){ for(int j = 1; j <= k; j++){ for(int k = 0; k < i; k++){ dp[i][j] = max(dp[k][j-1]*arr[k+1][i],dp[i][j]); } } } cout << dp[n-1][k] << endl; return 0; }
时间: 2024-11-04 20:05:01