#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 |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |