# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
316393 | Killer2501 | Kangaroo (CEOI16_kangaroo) | C++14 | 48 ms | 23160 KiB |
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>
#define pb push_back
#define vii vector<int>
#define task "teamwork"
#define pll pair<ll, ll>
#define pii pair< ll, pair< ll, ll > >
#define fi first
#define se second
using namespace std;
using ll = long long;
using ull = unsigned long long;
const int N = 2005;
const ll mod = 1e9+7;
//const ll base = 200;
ll m, n, k, t, T, ans, s, e, u, v, cs, cf, tong, lab[N];
ll a[N], b[N], d[N], c[N], x[N], dp[N][N];
//string s;
vector<ll> kq, adj[N];
set<ll> st;
void sol()
{
cin >> n >> cs >> cf;
if(cs > cf)swap(cs, cf);
dp[0][0] = 1;
for(int i = 1; i < n; i ++)
{
for(int j = 0; j <= i; j ++)
{
if(i == cs || i == cf)
{
dp[i][j] = (dp[i][j] + dp[i-1][j+1] * (j + 1)) % mod;
dp[i][j] = (dp[i][j] + dp[i-1][j]) % mod;
}
else
{
if(j)dp[i][j] = (dp[i][j] + dp[i-1][j-1] ) % mod;
if(j)dp[i][j] = (dp[i][j] + dp[i-1][j+1] * j * (j + 1) % mod ) % mod;
if(i > cs)dp[i][j] = (dp[i][j] + dp[i-1][j+1] * (j + 1) % mod ) % mod;
if(i > cf)dp[i][j] = (dp[i][j] + dp[i-1][j+1] * (j + 1) % mod ) % mod;
}
}
}
cout << dp[n-1][0];
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen(task".in", "r"))
{
freopen(task".in","r",stdin);
freopen(task".out","w",stdout);
}
int ntest = 1;
//cin >> ntest;
while(ntest -- > 0)
sol();
}
/*
*/
Compilation message (stderr)
# | 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... |