#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll Mod = 1e9 + 7;
ll fx(ll a, ll b) { return (a + b) % Mod; }
ll mx(ll a, ll b) { return (a * b) % Mod; }
ll binpow(ll a, ll b)
{
if (b == 0)
return 1ll;
ll s = binpow(a, b / 2);
if (b % 2)
return mx(mx(s, s), a);
return mx(s, s);
}
ll dp[351][351][2];
ll fact[351], binnom[351][351];
ll calc(ll n, ll k)
{
if (k == 0)
return 1;
return mx(fact[n], binpow(mx(fact[n - k], fact[k]), Mod - 2));
}
int main()
{
int n;
scanf("%d", &n);
fact[0] = fact[1] = 1;
for (ll i = 2; i <= n; i++)
fact[i] = mx(fact[i - 1], i);
for (ll i = 0; i <= n; i++)
for (ll j = 0; j <= i; j++)
binnom[i][j] = calc(i, j);
dp[0][n][0] = 1;
for (int i = 0; i < n; i++)
for (int j = 0; j <= n; j++)
for (int f = 0; f <= 1; f++)
{
for (int u = 0; u <= j; u++)
{
if (u == i + 1)
dp[i + 1][j - u][1] = fx(dp[i + 1][j - u][1], mx(binnom[j][u], dp[i][j][f]));
else
dp[i + 1][j - u][f] = fx(dp[i + 1][j - u][f], mx(binnom[j][u], dp[i][j][f]));
}
}
printf("%lld\n", dp[n][0][1]);
}
Compilation message (stderr)
zapina.cpp: In function 'int main()':
zapina.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |