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 <bits/stdc++.h>
using namespace std;
int MOD = 1000007;
vector<int> seq;
vector<vector<vector<int> > > dp;
int recurse(int strict, int i, int maxN) {
if (dp[strict][i][maxN] > -1) {
return dp[strict][i][maxN];
}
if (i==0) {
if (strict) return dp[strict][i][maxN] = seq[i];
else return dp[strict][i][maxN] = (maxN + 1);
}
int poss = 0;
if (strict) {
poss += recurse(1, i-1, max(seq[i], maxN));
poss %= MOD;
if (seq[i]>1) poss += (seq[i]-1) * recurse(0, i-1, maxN);
poss %= MOD;
} else {
poss += maxN * recurse(0, i-1, maxN);
poss %= MOD;
poss += recurse(0, i-1, maxN+1);
poss %= MOD;
}
dp[strict][i][maxN] = poss;
return poss;
}
int main() {
int N;cin>>N;
seq.assign(N, 0);
dp.assign(2, vector<vector<int> >(N, vector<int>(N+1, -1)));
for (int i = N-1; i >= 0; i--) {
cin >> seq[i];
}
cout << recurse(1, N-1, 1) << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |