제출 #610946

#제출 시각아이디문제언어결과실행 시간메모리
6109462fat2code캥거루 (CEOI16_kangaroo)C++17
0 / 100
0 ms340 KiB
#include "bits/stdc++.h" #define fr first #define sc second #define all(s) s.begin(), s.end() #define rc(s) return cout << s, 0 using namespace std; const int mod = 1e9 + 7; const int nmax = 2005; int n, s, t, dp[nmax][nmax]; int32_t main(){ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0); //freopen("input.in", "r", stdin); cin >> n >> s >> t; dp[0][0] = 1; if(s > t) swap(s, t); for(int i=1;i<=n-1;i++){ for(int j=1;j<=i;j++){ if(i < s){ dp[i][j] = (dp[i - 1][j + 1] * ((j + 1) * j / 2 % mod) % mod + dp[i - 1][j - 1]) % mod; } else if(i == s){ dp[i][j] = (dp[i - 1][j] * j % mod + dp[i - 1][j - 1]) % mod; } else if(i > s && i < t){ dp[i][j] = (dp[i - 1][j + 1] * (j * (j - 1) / 2 % mod) % mod + dp[i - 1][j + 1] * j % mod) % mod; dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % mod; } else if(i == t){ dp[i][j] = (dp[i - 1][j] + dp[i - 1][j] * (j - 1) % mod) % mod; } else{ dp[i][j] = (dp[i - 1][j + 1] * ((j + 1) * j / 2 % mod) % mod + dp[i - 1][j - 1]) % mod; } } } if(t == n){ cout << dp[n - 1][1] << '\n'; } else{ cout << dp[n - 1][2] << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...