#include <bits/stdc++.h>
using namespace std;
void setup()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const long long mod = 1000007;
long long n, f[10002], g[10002], a[10002], p[10002], res = 1;
int main()
{
setup();
cin >> n;
for (long long i = 1; i <= n; ++i)
{
cin >> a[i];
p[i] = max(p[i - 1], a[i]);
}
reverse(a + 1, a + 1 + n);
reverse(p + 1, p + 1 + n);
fill_n(f, n + 2, 1);
// f[i] is the number of team selection available if the maximum a[i] in the prefix is i
for (long long i = 1; i <= n; ++i)
{
for (long long j = 1; j <= n; ++j)
{
g[j] = (f[j] * j + f[j + 1]) % mod;
}
(res += (a[i] - 1) * f[p[i + 1]]) %= mod;
for (long long j = 1; j <= n; ++j)
{
f[j] = g[j];
}
}
cout << res;
return 0;
}
# | 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... |