This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "peru.h"
#include <iostream>
#include <deque>
#include <queue>
#include <vector>
using namespace std;
constexpr int NMAX = 2005;
constexpr int BASE = 23;
constexpr int MOD = 1e9 + 7;
typedef long long LL;
constexpr LL INF = 1e18;
LL dp[NMAX];
int Power[NMAX];
int solve(int n, int k, int* v){
dp[0] = 0;
for (int i = 1; i <= n; ++ i ) {
int Max = v[i-1];
dp[i] = INF;
for (int j = i-1; j >= max(0, i - k); -- j ) {
dp[i] = min(dp[i], dp[j] + Max);
if (j != 0) Max = max(Max, v[j-1]);
}
}
int ans = 0;
Power[0] = 1;
for (int i = 1; i <= n; ++ i )
Power[i] = (1LL * Power[i-1] * 23) % MOD;
for (int i = 1; i <= n; ++ i )
ans = (1LL * ans + 1LL * Power[n-i] * dp[i]) % MOD;
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |