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>
using namespace std;
int N, K, dp[3009][3009], v0[3009], ways[3009];
const int mod = 1e9 + 7;
int add (int x, int y) {int ans = x + y; if (ans >= mod) ans -= mod; return ans;}
int subtract (int x, int y) {if (x >= y) return x - y; return x - y + mod;}
int mul (int x, int y) {return 1LL * x * y % mod;}
void adto (int &x, int y) {x += y; if (x >= mod) x -= mod;}
int power (int a, int b)
{
int p = 1;
for (int i=0; (1<<i) <= b; i++)
{
if (b & (1 << i)) p = mul (p, a);
a = mul (a, a);
}
return p;
}
int fac[200009], inv[200009];
void Prec (int lim){fac[0] = inv[0] = 1;for (int i=1; i<=lim; i++)fac[i] = mul (fac[i - 1], i);
inv[lim] = power (fac[lim], mod - 2);for (int i=lim - 1; i>=0; i--)inv[i] = mul (inv[i + 1], i + 1);}
int comb (int N, int K){int ans = mul (fac[N], inv[N - K]);ans = mul (ans, inv[K]);return ans;}
int coef[109][109];
int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);
scanf ("%d %d", &N, &K), K --, Prec (N + 1);
/*for (int i=1; i<=N; i++)
coef[i][i] = 1;
for (int i=1; i<=N; i++)
for (int j=1; j<i; j++)
for (int k=1; k<=N; k++)
coef[i][k] = subtract (coef[i][k], mul (coef[j][k], comb (i, j)));
for (int i=N; i>=1; i--)
for (int j=i + 1; j<=N; j++)
for (int k=1; k<=N; k++)
coef[i][k] = subtract (coef[i][k], mul (coef[j][k], comb (j, i)));
for (int i=1; i<=N; i++, printf ("\n"))
for (int j=1; j<=N; j++)
if (coef[i][j] >= mod - 100000) printf ("%3d ", coef[i][j] - mod);
else printf ("%3d ", coef[i][j]);
printf ("\n");
return 0;*/
dp[0][0] = 1;
/*for (int i=0; i<N; i++)
for (int j=0; j<=N; j++)
for (int k=1; j + k<=N; k++)
adto (dp[i + 1][j + k], mul (dp[i][j], inv[k]));
for (int i=0; i<=N; i++)
v0[i] = mul (fac[N], dp[N - i][N]);
that would be K! * stirling
*/
/*for (int i=1; i<=N; i++)
{
ways[i] = power (i, N);
for (int j=1; j<i; j++)
ways[i] = subtract (ways[i], mul (ways[j], comb (i, j)));
}
for (int i=0; i<=N; i++)
v0[i] = ways[N - i];*/
/*for (int K2=0; K2<=N; K2++)
for (int j=1; j<=N-K2; j++)
{
int curr = mul (power (j, N), comb (N - K2, j));
if (j % 2 == (N - K2) % 2) adto (v0[K2], curr);
else v0[K2] = subtract (v0[K2], curr);
}
for (int i=1; i<=N; i++)
printf ("%d ", v0[i]);
printf ("\n");
int ans = 0;
for (int K2=K; K2<=N; K2++)
{
int curr = mul (v0[K2], comb (K2, K));
if (K2 % 2 == K % 2) adto (ans, curr);
else ans = subtract (ans, curr);
}*/
int ans = 0;
for (int j=1; j + K<=N; j++)
{
int curr = mul (power (j, N), comb (N + 1, j + K + 1));
if (j % 2 == (N - K) % 2) adto (ans, curr);
else ans = subtract (ans, curr);
}
printf ("%d\n", ans);
return 0;
}
Compilation message (stderr)
asceticism.cpp: In function 'int main()':
asceticism.cpp:35:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d %d", &N, &K), K --, Prec (N + 1);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
# | 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... |