This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define END "\n"
#define rall(v) (v).rbegin(), (v).rend()
#define all(v) (v).begin(), (v).end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
constexpr ll modu = 1e9 + 7;
void solve(){
int n, a, b;
cin >> n >> a >> b;
if (a > b) swap(a, b);
vector<vector<ll>> dp(n + 1, vector<ll>(n + 2));
dp[0][0] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
if (i == a || i == b) dp[i][j] += dp[i - 1][j - 1] + dp[i - 1][j];
else {
if (i < a && i < b) {
dp[i][j] += (j * (dp[i - 1][j + 1] + dp[i - 1][j - 1]));
} else if (i > a && i < b) {
dp[i][j] += (j - 1) * (dp[i - 1][j + 1] + dp[i - 1][j - 1]) + dp[i - 1][j + 1];
} else {
dp[i][j] += (j - 2) * (dp[i - 1][j + 1] + dp[i - 1][j - 1]) + 2 * dp[i - 1][j + 1];
}
}
dp[i][j] %= modu;
}
}
cout << dp[n][1] << END;
}
int main()
{
fastio
int t = 1;
// cin>> t;
while(t--) solve();
return 0;
}
# | 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... |