记录编号 193594 评测结果 AAAAAAAAAA
题目名称 [NOIP 2000PJ]乘积最大 最终得分 100
用户昵称 Gravatar啊吧啦吧啦吧 是否通过 通过
代码语言 C++ 运行时间 0.002 s
提交时间 2015-10-14 21:41:42 内存使用 0.32 MiB
显示代码纯文本
#include <iostream>
#include <string>
#include <cstdio>
#include <fstream>

using namespace std;

ifstream fin("cjzd.in");
ofstream fout("cjzd.out");
#define cin fin
#define cout fout
const long long MAXN(50), MAXK(10);
long long n, k, dp[MAXN][MAXK];
string num;
inline long long tonumber(string);

main()
{
//	cout << sizeof(dp) / 1024.0;
	cin >> n >> k >> num;
	fin.close();
	
	dp[0][0] = tonumber(num.substr(0, 1));
	for (long long i = 1; i < n; ++i)
		for (long long j = 0; j <= min(i, k); ++j)
			if (j == 0)
				dp[i][j] = tonumber(num.substr(0, i + 1));
			else if (j == 1)
				dp[i][j] = dp[i - 1][j - 1];
			else
				for (long long l = 0; l < i; ++l)
					dp[i][j]=max(dp[i][j],dp[l][j-1]*tonumber(num.substr(l,
					i-l)));
	for (long i = k; i < n; ++i)
		dp[n][k] = max(dp[i][k] * tonumber(num.substr(i, n - i)), dp[n][k]);
	
	cout << dp[n][k];
	fout.close();
//	for (; ; );
}

inline long long tonumber(string s){
	long long x = 0;
	for (int i = 0; i < s.length(); ++i)
		x = x * 10 + s[i] - '0';
	return x;
}