#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
teams.cpp: In function 'int main()':
teams.cpp:34:9: warning: unused variable 'sum' [-Wunused-variable]
int sum = 0;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
640 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
2304 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
4224 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
19 ms |
8576 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
13 ms |
8448 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
19 ms |
8452 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |