Submission #316144

#TimeUsernameProblemLanguageResultExecution timeMemory
316144vipghn2003Kangaroo (CEOI16_kangaroo)C++14
0 / 100
1 ms384 KiB
#include<bits/stdc++.h> using namespace std; const int N=2005; const int mod=1e9+7; int n,cs,cf,dp[N][N]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin>>n>>cs>>cf; if(cs>cf) swap(cs,cf); dp[0][0]=1; for(int i=0;i<n;i++) { for(int j=0;j<=i;j++) { if(i+1==cs||i+1==cf) { dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod; if(j) dp[i+1][j-1]=(dp[i+1][j-1]+1ll*dp[i][j]*j%mod)%mod; continue; } dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j])%mod; if(j) { dp[i+1][j-1]=(dp[i+1][j-1]+1ll*j*(j-1)%mod*dp[i][j]%mod); if(i+1>cs) dp[i+1][j-1]=(dp[i+1][j-1]+1ll*dp[i][j]*j%mod)%mod; if(i+1>cf) dp[i+1][j-1]=(dp[i+1][j-1]+1ll*dp[i][j]*j%mod)%mod; } } } cout<<dp[n][0]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...