//In The Name Of ALLAH!
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define ld long double
#define endl '\n'
#define pb push_back
#define pf push_front
#define Zemur007 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define bpc __builtin_popcountll
#define btz __builtin_ctzll
#define all(x) x.begin() , x.end()
#define allr(x) x.rbegin() , x.rend()
#define F first
#define S second
#define pll pair<ll , ll>
#define turtle tuple<ll , ll , ll>
#define pss pair<string , string>
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define indexed_set tree<pll , null_type , less<pll> , rb_tree_tag , tree_order_statistics_node_update>
const ll sz = 2e3 + 5 , INF = 1e18 , MOD = 1e9 + 7;
ll dp[sz][sz];
//dp[i][j] ilk i ədəd istifadə etsək şərtə uyğun j dənə ayrı component yaransa yolların sayı
ll mul(ll a , ll b){
return ((a % MOD) * (b % MOD)) % MOD;
}
ll mask , i , j , l , k;
void solve(){
ll n , cs , cf; cin >> n >> cs >> cf;
dp[1][1] = 1;
ll used = 0;
for(i = 2 ; i <= n ; i++){
used += (i == cs || i == cf);
for(j = 1 ; j <= i ; j++){
if(i == cs || i == cf){
dp[i][j + 1] = (dp[i][j + 1] + dp[i - 1][j]) % MOD;
dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
}
else{
if(j + 1 <= i) dp[i][j + 1] = (dp[i][j + 1] + mul(dp[i - 1][j] , j + 1 - used));
dp[i][j - 1] = (dp[i][j - 1] + mul(dp[i - 1][j] , j - 1)) % MOD;
}
}
}
cout << dp[n][1] << endl;
}
signed main(){
Zemur007;
//open;
ll t = 1;
// cin >> t;
while(t--){
solve();
}
// for(ll testcase = 1 ; testcase <= t ; testcase++){
// cout << "Case " << testcase << ":" << endl;
// solve();
// }
}
| # | 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... |