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;
#define rep(i,a,b) for(int i = a; i<int(b);++i)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define trav(a,c) for(auto a: c)
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;
int main(){
cin.sync_with_stdio(false);
ll n;
cin>>n;
vi v(n);
rep(i,0,n) cin>>v[i];
vector<vector<int> > dp(n+1,vector<int>(n+1,1));
ll mod = 1e6+7;
rep(left,1,n+1)
rep(numTeams,1,n-left+1)
dp[left][numTeams] = (numTeams*dp[left-1][numTeams] + dp[left-1][numTeams+1])%mod;
ll numTeams = 1;
ll ans = 0;
rep(i,0,n){
ans = (ans + (v[i]-1)*dp[n-i-1][numTeams])%mod;
numTeams = max(v[i],numTeams);
}
cout<<(ans+1)%mod<<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... |