#include <bits/stdc++.h>
using namespace std;
const int mod = 1e6 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
int n;
vector<int> v;
int dp[10005][10005][2];
int f(int pos, int mx, int under) {
if(pos == n + 1) return under;
if(dp[pos][mx][under] != -1) return dp[pos][mx][under];
long long ans = 0;
if(under) {
ans = (ans + 1ll * mx * f(pos+1, mx, 1)) % mod;
if(mx+1 <= pos) ans = (ans + f(pos+1, mx+1, 1)) % mod;
} else {
for(int i=1; i<=min(pos, 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 |
Runtime error |
11 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
11 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
11 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
11 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
10 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
11 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
11 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
10 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
11 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
11 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |