许诺 • 13天前
#include <iostream>
#include <vector>
using namespace std;
int main() {
int S;
cin >> S;
vector<int> sum_div(S + 1, 0);
for (int i = 1; i <= S; ++i) {
for (int j = 1; j < i; ++j) {
if (i % j == 0) {
sum_div[i] += j;
}
}
}
vector<int> dp(S + 1, 0);
for (int i = 1; i <= S; ++i) {
for (int j = S; j >= i; --j) {
dp[j] = max(dp[j], dp[j - i] + sum_div[i]);
}
}
int max_sum = 0;
for (int j = 0; j <= S; ++j) {
if (dp[j] > max_sum) {
max_sum = dp[j];
}
}
cout << max_sum << endl;
return 0;
}
评论:
请先登录,才能进行评论