1 条题解
-
0
为了防止有人
抄袭参考我的代码,特意写成这样QWQ勿喷#include <iostream> #include <string> #include <vector> using namespace std; vector<int> mul(vector<int> a, vector<int> b) {vector<int> res(a.size() + b.size(), 0);for (int i = 0; i < a.size(); ++i)for (int j = 0; j < b.size(); ++j) {res[i + j] += a[i] * b[j];res[i + j + 1] += res[i + j] / 10;res[i + j] %= 10;}while (res.size() > 1 && res.back() == 0) res.pop_back();return res;} vector<int> maxv(vector<int> a, vector<int> b) {if (a.size() != b.size()) return a.size() > b.size() ? a : b;for (int i = a.size() - 1; i >= 0; --i)if (a[i] != b[i]) return a[i] > b[i] ? a : b;return a;} vector<int> numt(const string &s) {vector<int> res;for (int i = s.size() - 1; i >= 0; --i) res.push_back(s[i] - '0');return res;} int main() { int n, k;cin >> n >> k;string s;cin >> s;vector<vector<vector<int>>> dp(k + 2, vector<vector<int>>(n + 2));for (int i = 1; i <= n; ++i) dp[0][i] = numt(s.substr(0, i));for (int m = 1; m <= k; ++m)for (int i = m + 1; i <= n; ++i)for (int j = m; j < i; ++j) {vector<int> t = mul(dp[m - 1][j], numt(s.substr(j, i - j)));if (dp[m][i].empty() || maxv(t, dp[m][i]) == t) dp[m][i] = t;}for (int i = dp[k][n].size() - 1; i >= 0; --i) cout << dp[k][n][i]; return 0; }
信息
- ID
- 5076
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 6
- 标签
- 递交数
- 54
- 已通过
- 8
- 上传者