Submission #165796

#TimeUsernameProblemLanguageResultExecution timeMemory
165796luciocf캥거루 (CEOI16_kangaroo)C++14
100 / 100
80 ms16324 KiB
#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));
}

Compilation message (stderr)

kangaroo.cpp: In function 'int main()':
kangaroo.cpp:45:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &n, &cs, &cf);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...