이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#pragma GCC target("popcnt")
#define fi first
#define se second
#define lc id<<1
#define rc id<<1^1
#define val f[i][j]
const int mod = 1e9 + 7;
double begintime, endtime;
using namespace std;
inline void CALC_TIME()
{
endtime = clock();
cout << "\nexecution time : " << (endtime - begintime + 1) / 1000 << " s";
}
void add(int &x, int y)
{
x += y;
if (x >= mod)
x -= mod;
}
int mul(int x, int y)
{
return 1LL * x * y % mod;
}
typedef pair<int, int> pii;
int n, cs, cf;
int f[2008][2008];
int dq(int i, int j)
{
if (val != -1)
return val;
if (i == n)
return val = (j == 1);
int res = 0;
if (i + 1 == cs || i + 1 == cf)
{
add(res, dq(i + 1, j));
add(res, dq(i + 1, j + 1));
return val = res;
}
if (j > 1)
add(res, mul(j - 1, dq(i + 1, j - 1)));
add(res, mul(j + 1 - (i + 1 > cs) - (i + 1 > cf), dq(i + 1, j + 1)));
return val = res;
}
int main()
{
begintime = clock();
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
memset(f, -1, sizeof(f));
cin >> n >> cs >> cf;
cout << dq(0, 0);
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... |