# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
165796 | luciocf | 캥거루 (CEOI16_kangaroo) | C++14 | 80 ms | 16324 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3+10;
const int mod = 1e9+7;
int n;
int cs, cf;
int dp[maxn][maxn];
int solve(int pos, int cc)
{
if (pos == n+1 && cc != 1) return 0;
if (pos == n+1) return 1;
if (dp[pos][cc] != -1) return dp[pos][cc];
int ans = 0;
if (pos == cs || pos == cf)
{
ans = (ans + solve(pos+1, cc))%mod;
ans = (ans + solve(pos+1, cc+1))%mod;
return dp[pos][cc] = ans;
}
if (cc >= 2)
{
ans = (1ll*ans + 1ll*(cc-1)*solve(pos+1, cc+1))%mod;
ans = (1ll*ans + 1ll*(cc-1)*solve(pos+1, cc-1))%mod;
}
if (pos < cs)
ans = (1ll*ans + 1ll*solve(pos+1, cc+1))%mod;
if (pos < cf)
ans = (1ll*ans + 1ll*solve(pos+1, cc+1))%mod;
return dp[pos][cc] = ans;
}
int main(void)
{
scanf("%d %d %d", &n, &cs, &cf);
if (cs > cf) swap(cs, cf);
memset(dp, -1, sizeof dp);
printf("%d\n", solve(2, 1));
}
컴파일 시 표준 에러 (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... |