제출 #999579

#제출 시각아이디문제언어결과실행 시간메모리
999579codefox캥거루 (CEOI16_kangaroo)C++14
100 / 100
49 ms31836 KiB
#include<bits/stdc++.h> using namespace std; #define int long long int mod = 1e9+7; int32_t main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); int n, a, b; cin >> n >> a >> b; vector<vector<int>> dp(n+1, vector<int>(n+1, 0)); dp[1][1] = 1; int bb = 0; if (a==1) bb++; if (b==1) bb++; for (int i = 2; i <= n; i++) { if (i==a) { dp[i] = vector<int>(dp[i-1]); i++; bb++; } if (i==b) { if (n%2==0) { for (int j = 2; j <= n; j++) { dp[i][j] += dp[i-1][j-1]; } } else { dp[i] = vector<int>(dp[i-1]); } i++; bb++; } if (i==a) { dp[i] = vector<int>(dp[i-1]); i++; bb++; } if (i>n) break; for (int j = 2; j <=n; j++) { dp[i][j] += dp[i-1][j-1]*(j); dp[i][j] -= dp[i-1][j-1]*bb; dp[i][j-1] += dp[i-1][j]*(j-1); } for (int j = 1; j <= n; j++) dp[i][j]%=mod; } int sol = dp[n][1]; dp.assign(n+1, vector<int>(n+1, 0)); dp[1][1] =1; bb=0; if (a==1) bb++; if (b==1) bb++; for (int i = 2; i <= n; i++) { if (i==a) { for (int j = 2; j <= n; j++) { dp[i][j] += dp[i-1][j-1]; } i++; bb++; } if (i==b) { if (n%2) { for (int j = 2; j <= n; j++) { dp[i][j] += dp[i-1][j-1]; } } else { dp[i] = vector<int>(dp[i-1]); } i++; bb++; } if (i==a) { for (int j = 2; j <= n; j++) { dp[i][j] += dp[i-1][j-1]; } i++; bb++; } if (i>n) break; for (int j = 2; j <=n; j++) { dp[i][j] += dp[i-1][j-1]*(j); dp[i][j] -= dp[i-1][j-1]*bb; dp[i][j-1] += dp[i-1][j]*(j-1); } for (int j = 1; j <= n; j++) dp[i][j]%=mod; } cout << (sol + dp[n][1])%mod; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...