许诺 • 1天前
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> p(n + 1);
for (int i = 1; i <= n; i++) {
cin >> p[i];
}
vector<int> dp(n + 1, INT_MAX);
dp[0] = 0;
for (int i = 1; i <= n; i++) {
int max_val = 0;
for (int j = 1; j <= min(i, 255); j++) {
max_val = max(max_val, p[i - j + 1]);
int bits = 0;
if (max_val > 0) {
bits = 32 - __builtin_clz(max_val);
}
if (bits == 0) bits = 1;
dp[i] = min(dp[i], dp[i - j] + j * bits + 11);
}
}
cout << dp[n] << endl;
return 0;
}
评论:
请先登录,才能进行评论