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>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 11000;
const ll mod = 1000007;
int dp[maxn][maxn];
int n, arr[maxn];
bool f[maxn];
int count_pref(vector<int>v, int limit) {
int maxv = 0;
for(int i:v) maxv = max(maxv, i);
memset(dp, 0, sizeof(dp));
dp[v.size()][maxv] = 1;
if(maxv > limit) return 0;
for(int i=v.size()+1;i<=n;i++) {
for(int j=maxv;j<=limit;j++) {
dp[i][j] = (j * dp[i-1][j])%mod + dp[i-1][j-1];
dp[i][j] %= mod;
}
}
ll result = 0LL;
for(int i=1;i<=limit;i++) {
result += dp[n][i];
result %= mod;
}
return result;
}
int main() {
cin>>n;
int maxv = 0;
for(int i=1;i<=n;i++) {
cin>>arr[i];
if(arr[i] > maxv) {
maxv = arr[i];
f[i] = true;
}
}
vector<int>v = {1};
ll result = 0LL;
for(int i=2;i<=n;i++) {
for(int j=1;j<arr[i];j++) {
v.pb(j);
result += count_pref(v, maxv);
result %= mod;
v.pop_back();
}
v.pb(arr[i]);
}
cout<<(result+1)%mod<<"\n";
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... |