이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=long long;
const ll MOD=1000000007LL;
template<typename T> void chmax(T &a,T b){a=max(a,b);}
template<typename T> void chmin(T &a,T b){a=min(a,b);}
int main(){
ll n,k;cin>>n>>k;if(n>3000)return 0;
vector<vector<ll>> dp(n+10,vector<ll>(n+10));
dp[0][0]=1;
for(ll i=1;i<=n;i++){
for(ll j=0;j<i;j++){//i+1通り挿入できる
dp[i][j]+=dp[i-1][j]*(j+1LL)%MOD;
if(j>0){
dp[i][j]+=dp[i-1][j-1]*(i-j)%MOD;
}
dp[i][j]%=MOD;
}
}
cout<<dp[n][k-1]<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |