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>
#ifdef LOCAL
#include <bits/debug.hpp>
#endif // LOCAL
#define ll long long
#define all(x) x.begin(), x.end()
#define Neco "Kangaroo"
#define resp(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define getbit(x,i) ((x >> i)&1)
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define cntbit(x) __builtin_popcountll(x)
#define fi(i, a, b) for(int i = a; i <= b; i++)
#define fid(i, a, b) for(int i = a; i >= b; i--)
#define maxn (int) 2e3 + 7
using namespace std;
const ll mod = 1e9 + 7; //972663749
const ll base = 911382323;
/// dem so hoan vi co a la phan tu dau va b la phan tu cuoi
/// hoan vi phai thoa man theo kieu len xuong : /\/\/\/, ko dc cung xuong hoac cung len
/// connected component dp, vi co dinh dau cuoi nen ko can phai xet den thao tac chen vao ngoai tru luc them dau cuoi :0
/// neu ko co dau cuoi thi bat buoc phai co thao tac chen
/// vi ko co thao tac chen va them cac phan tu theo thu tu tang dan, nen moi tplt ko chua dau cuoi phai tm tinh chat /\/\/\, cai dau phai la len va cai cuoi luon la xuong
int n, st, fn;
ll dp[maxn][maxn]; /// duyet den i va co j tplt
void solve()
{
cin >> n >> st >> fn;
dp[1][1] = 1;
int w = 0;
fi(i, 2, n) fi(j, 1, i) {
w += i == st || i == fn;
if(i == st || i == fn) {
dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % mod;
}
else {
dp[i][j] = (dp[i][j] + (j + 1 - w) * dp[i - 1][j - 1]) % mod;
dp[i][j] = (dp[i][j] + j * dp[i - 1][j + 1]) % mod;
}
}
cout << dp[n][1];
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen(Neco".inp", "r")) {
freopen(Neco".inp", "r", stdin);
freopen(Neco".out", "w", stdout);
}
int nTest = 1;
// cin >> nTest;
while(nTest--)
{
solve();
}
return 0;
}
Compilation message (stderr)
kangaroo.cpp: In function 'int main()':
kangaroo.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | freopen(Neco".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
kangaroo.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
66 | freopen(Neco".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |