#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
using namespace std;
ll n,dp[350][350],mod=7+1e9,C[350][350];
bool use[350][350];
ll coeff(ll N,ll K){
if( K==0 || K==N ) return 1;
if( C[N][K] ) return C[N][K];
return C[N][K] = (coeff( N-1 , K-1 ) + coeff( N-1 , K ) )%mod;
}
ll expBin( ll A , ll B ){
if( !B ) return 1LL;
ll myAns = expBin( A , B/2 );
myAns = (myAns*myAns)%mod;
if( B&1 ) myAns = (myAns*A)%mod;
return myAns;
}
ll fn( ll pos , ll T ){
if( !pos || !T ) return 0LL;
if( use[pos][T] ) return dp[pos][T];
use[pos][T] = true;
ll myAns = 0LL;
if( pos <= T ){
myAns = ( coeff( T , pos )*expBin( pos-1 , T-pos ) )%mod;
}
for(ll i=0; i<=T; i++){
if( i==pos ) continue;
myAns = ( myAns + ((coeff( T , i )*fn( pos-1 , T-i ))%mod) )%mod;
}
return dp[pos][T] = myAns;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
cout << fn( n , n );
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
5 ms |
380 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
5 ms |
380 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
175 ms |
1912 KB |
Output is correct |
18 |
Correct |
6 ms |
632 KB |
Output is correct |
19 |
Correct |
42 ms |
1400 KB |
Output is correct |
20 |
Correct |
5 ms |
504 KB |
Output is correct |
21 |
Correct |
233 ms |
2040 KB |
Output is correct |
22 |
Correct |
29 ms |
1148 KB |
Output is correct |
23 |
Correct |
7 ms |
632 KB |
Output is correct |
24 |
Correct |
51 ms |
1404 KB |
Output is correct |
25 |
Correct |
38 ms |
1272 KB |
Output is correct |
26 |
Correct |
70 ms |
1532 KB |
Output is correct |
27 |
Correct |
325 ms |
2296 KB |
Output is correct |
28 |
Correct |
328 ms |
2412 KB |
Output is correct |
29 |
Correct |
340 ms |
2400 KB |
Output is correct |
30 |
Correct |
336 ms |
2424 KB |
Output is correct |
31 |
Correct |
338 ms |
2424 KB |
Output is correct |
32 |
Correct |
343 ms |
2384 KB |
Output is correct |
33 |
Correct |
347 ms |
2424 KB |
Output is correct |
34 |
Correct |
347 ms |
2424 KB |
Output is correct |
35 |
Correct |
352 ms |
2424 KB |
Output is correct |
36 |
Correct |
353 ms |
2424 KB |
Output is correct |
37 |
Correct |
359 ms |
2452 KB |
Output is correct |