#include "peru.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M = 1e9 + 7;
const ll INF = numeric_limits<ll>::max()/2;
int solve(int n, int k, int* v){
vector<ll> dp (n+1, INF);
dp[0] = 0;
ll sol = 0;
vector<ll> ve (n, 1);
for (int i = 1; i < n; i++) {
ve[i] = (ve[i-1] * 23) % M;
}
for (int i = 0; i < n; i++) {
ll cur = v[i];
for (int j = i; j >= max(0, i-k+1); j--) {
cur = max(cur, (ll) v[j]);
dp[i+1] = min(dp[i+1], dp[j] + cur);
}
sol += (ve[n - i - 1] * dp[i+1]) % M;
sol %= M;
}
return sol;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |