#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[1005][1005][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];
int ans = 0;
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8280 KB |
Output is correct |
2 |
Correct |
1 ms |
8284 KB |
Output is correct |
3 |
Correct |
1 ms |
8284 KB |
Output is correct |
4 |
Correct |
1 ms |
8284 KB |
Output is correct |
5 |
Correct |
2 ms |
8284 KB |
Output is correct |
6 |
Correct |
1 ms |
8280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8280 KB |
Output is correct |
2 |
Correct |
1 ms |
8284 KB |
Output is correct |
3 |
Correct |
2 ms |
8280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8280 KB |
Output is correct |
2 |
Correct |
1 ms |
8284 KB |
Output is correct |
3 |
Correct |
1 ms |
8284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
8284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8280 KB |
Output is correct |
2 |
Correct |
2 ms |
8284 KB |
Output is correct |
3 |
Correct |
3 ms |
8284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
8536 KB |
Output is correct |
2 |
Correct |
78 ms |
8280 KB |
Output is correct |
3 |
Correct |
82 ms |
8284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
625 ms |
8284 KB |
Output is correct |
2 |
Correct |
617 ms |
8408 KB |
Output is correct |
3 |
Correct |
607 ms |
8284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
634 ms |
8440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
647 ms |
8428 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
621 ms |
8528 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |