#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define crep(i,x,n) for(int i=x;i<n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define vec(...) vector<__VA_ARGS__>
#define _3qplfh5 ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
using pii=pair<int,int>;
using vi=vector<int>;
using vll=vector<long long>;
//snuke's mod int
template <ll mod>
struct modint{
ll x; // typedef long long ll;
modint(ll x=0):x((x%mod+mod)%mod){}
modint operator-()const{ return modint(-x);}
modint& operator+=(const modint a){ if((x+=a.x)>=mod) x-=mod; return *this; }
modint& operator-=(const modint a){ if((x+=mod-a.x)>=mod) x-=mod; return *this; }
modint& operator*=(const modint a){ (x*=a.x)%=mod; return *this; }
modint operator+(const modint a)const{ modint res(*this); return res+=a; }
modint operator-(const modint a)const{ modint res(*this); return res-=a; }
modint operator*(const modint a)const{ modint res(*this); return res*=a; }
modint pow(ll n) const {
modint res=1,x(*this);
while(n){
if(n&1)res*=x;
x*=x;
n>>=1;
}
return res;
}
modint inv() const { return pow(mod-2); }
};
using mint=modint<1000000007>;
const int mxn=400;
mint cnktable[mxn][mxn];
void precomb(){
rep(i,mxn-1){
rep(j,mxn-1){
if(!i){
cnktable[i][j]=!j;
}else{
cnktable[i][j]=(i==j or j==0?1:cnktable[i-1][j-1]+cnktable[i-1][j]);
}
}
}
}
int main(){
_3qplfh5;
precomb();
int n;
cin>>n;
vec(vec(mint)) dp(n+1,vec(mint)(2)),nedp;
dp[0][0]=1;
rep(i,n){
int need=i+1;
nedp=vec(vec(mint))(n+1,vec(mint)(2));
rep(j,n+1){
rep(k,(n-j)+1){
rep(t,2){
int net=t;
if(k==need) net=1;
nedp[j+k][net]+=dp[j][t]*cnktable[n-j][k];
}
}
}
swap(dp,nedp);
// cout<<dp[1][1].x<<"\n";
}
cout<<dp[n][1].x<<"\n";
//
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1484 KB |
Output is correct |
2 |
Correct |
1 ms |
1484 KB |
Output is correct |
3 |
Correct |
1 ms |
1484 KB |
Output is correct |
4 |
Correct |
1 ms |
1484 KB |
Output is correct |
5 |
Correct |
1 ms |
1484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1484 KB |
Output is correct |
2 |
Correct |
1 ms |
1484 KB |
Output is correct |
3 |
Correct |
1 ms |
1484 KB |
Output is correct |
4 |
Correct |
1 ms |
1484 KB |
Output is correct |
5 |
Correct |
1 ms |
1484 KB |
Output is correct |
6 |
Correct |
1 ms |
1484 KB |
Output is correct |
7 |
Correct |
1 ms |
1484 KB |
Output is correct |
8 |
Correct |
1 ms |
1484 KB |
Output is correct |
9 |
Correct |
1 ms |
1484 KB |
Output is correct |
10 |
Correct |
1 ms |
1484 KB |
Output is correct |
11 |
Correct |
1 ms |
1484 KB |
Output is correct |
12 |
Correct |
1 ms |
1484 KB |
Output is correct |
13 |
Correct |
1 ms |
1484 KB |
Output is correct |
14 |
Correct |
1 ms |
1484 KB |
Output is correct |
15 |
Correct |
1 ms |
1484 KB |
Output is correct |
16 |
Correct |
2 ms |
1484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1484 KB |
Output is correct |
2 |
Correct |
1 ms |
1484 KB |
Output is correct |
3 |
Correct |
1 ms |
1484 KB |
Output is correct |
4 |
Correct |
1 ms |
1484 KB |
Output is correct |
5 |
Correct |
1 ms |
1484 KB |
Output is correct |
6 |
Correct |
1 ms |
1484 KB |
Output is correct |
7 |
Correct |
1 ms |
1484 KB |
Output is correct |
8 |
Correct |
1 ms |
1484 KB |
Output is correct |
9 |
Correct |
1 ms |
1484 KB |
Output is correct |
10 |
Correct |
1 ms |
1484 KB |
Output is correct |
11 |
Correct |
1 ms |
1484 KB |
Output is correct |
12 |
Correct |
1 ms |
1484 KB |
Output is correct |
13 |
Correct |
1 ms |
1484 KB |
Output is correct |
14 |
Correct |
1 ms |
1484 KB |
Output is correct |
15 |
Correct |
1 ms |
1484 KB |
Output is correct |
16 |
Correct |
2 ms |
1484 KB |
Output is correct |
17 |
Correct |
61 ms |
1484 KB |
Output is correct |
18 |
Correct |
2 ms |
1564 KB |
Output is correct |
19 |
Correct |
14 ms |
1592 KB |
Output is correct |
20 |
Correct |
1 ms |
1484 KB |
Output is correct |
21 |
Correct |
82 ms |
1564 KB |
Output is correct |
22 |
Correct |
12 ms |
1588 KB |
Output is correct |
23 |
Correct |
2 ms |
1484 KB |
Output is correct |
24 |
Correct |
18 ms |
1600 KB |
Output is correct |
25 |
Correct |
14 ms |
1484 KB |
Output is correct |
26 |
Correct |
24 ms |
1484 KB |
Output is correct |
27 |
Correct |
112 ms |
1564 KB |
Output is correct |
28 |
Correct |
115 ms |
1612 KB |
Output is correct |
29 |
Correct |
123 ms |
1612 KB |
Output is correct |
30 |
Correct |
115 ms |
1568 KB |
Output is correct |
31 |
Correct |
120 ms |
1612 KB |
Output is correct |
32 |
Correct |
117 ms |
1612 KB |
Output is correct |
33 |
Correct |
117 ms |
1604 KB |
Output is correct |
34 |
Correct |
117 ms |
1612 KB |
Output is correct |
35 |
Correct |
126 ms |
1600 KB |
Output is correct |
36 |
Correct |
122 ms |
1612 KB |
Output is correct |
37 |
Correct |
120 ms |
1612 KB |
Output is correct |