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;
using ll = long long;
const int maxn = 1e4+4, M = 1e9+7;
int n, a[maxn];
void madd(int& a, int b) {
a = (a+b) % M;
}
/*
* f(i,j) = # combinations, w/ i spaces left, that can be up to j
* f(i,j) = j*f(i-1,j) + f(i-1,j+1)
* f(0,x) = 1
* f(1,x) = x
* f(2,x) = j*x+x+1 = (j+1)*x+1
*
* */
int dp[1003][1003];
int main()
{
//ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 0; i < 1003; i++) {
dp[1][i] = i;
}
int sum = 0;
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= n-i; j++) {
dp[i][j] = (j-1)*dp[i-1][j] + dp[i-1][j+1];
//printf("[%d][%d]: %d\n",i,j,dp[i][j]);
//cout << dp[i][j] << ' ';
//madd(sum,dp[i][j]);
}
/*
cout << '\n';
cout << i << ": " << sum << '\n';
*/
}
int ans = 0;
for (int i = 1; i <= n; i++) {
madd(ans,dp[n+1-i][a[i]-1]);
}
madd(ans,1);
cout << ans << '\n';
}
Compilation message (stderr)
teams.cpp: In function 'int main()':
teams.cpp:34:9: warning: unused variable 'sum' [-Wunused-variable]
int sum = 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... |