#include <bits/stdc++.h>
#define int long long
using namespace std;
int MOD = 1e9+7;
int memo[1010][1010][2];
int maxi[1010],arr[1010];
int n;
int dp(int pos,int largest,int ssf){
if (pos == n) return 1;
if (memo[pos][largest][ssf] != -1) return memo[pos][largest][ssf];
if (ssf){
int curnum = arr[pos];
int ans = ((curnum-1)*dp(pos+1,largest,0))%MOD;
ans += dp(pos+1,max(largest,curnum),1);
return memo[pos][largest][ssf] = ans%MOD;
}
else{
int ans = (largest*dp(pos+1,largest,0))%MOD + dp(pos+1,largest+1,0);
return memo[pos][largest][ssf] = ans%MOD;
}
}
main(){
cin >> n;
for (int i = 0; i < n; i++){
int x;
cin >> x;
arr[i] = x;
if (i == 0) maxi[i] = x;
else maxi[i] = max(maxi[i-1],x);
}
for (int i = 0; i < 1010; i++) for (int j = 0; j < 1010; j++) memo[i][j][0] = memo[i][j][1] =-1;
cout << dp(0,0,1);
}
Compilation message
teams.cpp:22:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
16256 KB |
Output is correct |
2 |
Correct |
13 ms |
16256 KB |
Output is correct |
3 |
Correct |
12 ms |
16256 KB |
Output is correct |
4 |
Correct |
13 ms |
16256 KB |
Output is correct |
5 |
Correct |
12 ms |
16256 KB |
Output is correct |
6 |
Correct |
12 ms |
16256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
16256 KB |
Output is correct |
2 |
Correct |
13 ms |
16256 KB |
Output is correct |
3 |
Correct |
13 ms |
16256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
16256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
16336 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
16256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
16256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
20 ms |
16384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
36 ms |
33016 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
34 ms |
33016 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
35 ms |
33016 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |