/* Will you ever win? */
#include <iostream>
#include <fstream>
using namespace std;
const int nmax=10005;
const long long mod=1000*1000+7;
long long c[2][nmax],bell[nmax],mx[nmax],pw[nmax];
long long ans;
int v[nmax];
int n,i,j,use;
int main()
{
// freopen("data.in","r",stdin);
ios_base::sync_with_stdio(false);
cin>>n;
for(i=1;i<=n;i++)
{
cin>>v[i];
mx[i]=max(mx[i-1],1LL*v[i]);
}
bell[0]=1;
ans=v[n]-1;c[0][0]=1;
for(i=1;i<n;i++)
{
use=1-use;
c[use][0]=1;
for(j=1;j<=i;j++)
{
c[use][j]=(c[1-use][j]+c[1-use][j-1])%mod;
}
pw[0]=v[n-i]-1;
for(j=1;j<=i;j++)
pw[j]=(1LL*pw[j-1]*mx[n-i-1])%mod;
for(j=0;j<i;j++)
{
bell[i]=(1LL*bell[i]+(bell[j]*c[1-use][j]))%mod;
}
for(j=0;j<=i;j++)
ans=(ans+1LL*(bell[i-j]*c[use][j])*pw[j])%mod;
}
cout<<(ans+1)%mod;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
484 KB |
Output is correct |
3 |
Correct |
3 ms |
484 KB |
Output is correct |
4 |
Correct |
2 ms |
592 KB |
Output is correct |
5 |
Correct |
3 ms |
592 KB |
Output is correct |
6 |
Correct |
3 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
592 KB |
Output is correct |
2 |
Correct |
3 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
592 KB |
Output is correct |
2 |
Correct |
2 ms |
616 KB |
Output is correct |
3 |
Correct |
2 ms |
616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
620 KB |
Output is correct |
2 |
Correct |
2 ms |
624 KB |
Output is correct |
3 |
Correct |
2 ms |
624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
624 KB |
Output is correct |
2 |
Correct |
5 ms |
624 KB |
Output is correct |
3 |
Correct |
5 ms |
624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
624 KB |
Output is correct |
2 |
Correct |
14 ms |
624 KB |
Output is correct |
3 |
Correct |
12 ms |
624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
968 ms |
1056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
248 ms |
1056 KB |
Output is correct |
2 |
Correct |
247 ms |
1056 KB |
Output is correct |
3 |
Correct |
243 ms |
1056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
986 ms |
1104 KB |
Output is correct |
2 |
Correct |
991 ms |
1260 KB |
Output is correct |
3 |
Correct |
961 ms |
1308 KB |
Output is correct |