#include <bits/stdc++.h>
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
int n;
vector<int> v;
ll dp[1005][1005][2];
ll f(int pos, int mx, int under) {
if(pos == n + 1) return under;
if(dp[pos][mx][under] != -1) return dp[pos][mx][under];
ll ans = 0;
for(int i=1; i<=mx+1; i++) {
if(!under && i > v[pos]) continue;
ans = (ans + f(pos+1, max(mx, i), under|(i<v[pos]))) % mod;
}
return dp[pos][mx][under] = ans;
}
signed main() {
memset(dp, -1, sizeof(dp));
cin >> n;
v.resize(n+1);
for(int i=1; i<=n; i++) cin >> v[i];
cout << (f(2, 1, 0) + 1) % mod << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
16220 KB |
Output is correct |
2 |
Correct |
2 ms |
16220 KB |
Output is correct |
3 |
Correct |
2 ms |
16220 KB |
Output is correct |
4 |
Correct |
2 ms |
16220 KB |
Output is correct |
5 |
Correct |
2 ms |
16220 KB |
Output is correct |
6 |
Correct |
2 ms |
16220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
16220 KB |
Output is correct |
2 |
Correct |
2 ms |
16252 KB |
Output is correct |
3 |
Correct |
2 ms |
16220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
16216 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
16220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
16216 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
83 ms |
16268 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
621 ms |
16216 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
79 ms |
32852 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
76 ms |
32752 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
81 ms |
32772 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |