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;
typedef long long ll;
const ll N = 1e3 + 10;
const ll mod = 1e6 + 7;
ll n, ans, a[N], dp[N][N];
ll pwr(ll a, ll b){
if (b == 0)
return 1;
ll val = pwr(a, b/2);
val *= val;
val %= mod;
if (b&1)
val *= a;
val %= mod;
return val;
}
int main()
{
cin >> n;
for (ll i=1; i<=n; i++){
cin >> a[i];
}
for (ll i=n; i>0; i--){
for (ll j=1; j<=n; j++){
if (i==n){
dp[i][j] = dp[i][j-1] + 1;
continue;
}
dp[i][j] = (j-1) * dp[i+1][j] + dp[i+1][j+1];
dp[i][j] %= mod;
}
}
ll mx = 0;
for (ll i=1; i<n; i++){
ans += (a[i] - 1) * dp[i+1][mx+1];
ans %= mod;
mx = max(mx, a[i]);
}
ans += dp[n][a[n]];
ans %= mod;
cout << ans << 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... |