#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define bigint __int128
#define emb emplace_back
#define pb push_back
#define pii pair <int, int>
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define Task ""
#define MASK(k) (1ull << k)
#define bitcnt(k) __builtin_popcount(k)
#define testBit(n, k) ((n >> k) & 1)
#define flipBit(n, k) (n ^ (1ll << k))
#define offBit(n, k) (n & ~MASK(k))
#define onBit(n, k) (n | (1ll << k))
template <class T> bool minimize(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool maximize(T &a, T b) {if (a < b) {a = b; return true;} return false;}
const int N = 1e5 + 5, lim = 60, mod = 1e9 + 7;
const ll INF = 1e18;
int n, k;
void add(int &a, int b) {
if ((a += b) >= mod) a -= mod;
}
void sub(int &a, int b) {
if ((a -= b) < 0) a += mod;
}
int diff(int a, int b) {
sub(a, b); return a;
}
namespace sub1 {
int f[12];
void solve() {
vector <int> p(n); iota(all(p), 0);
// p <-> pos
int ans = 0;
do {
int cnt = 1;
for (int i = 0; i < n - 1; i++)
cnt += p[i] > p[i + 1];
ans += cnt == k;
} while (next_permutation(all(p)));
cout << ans;
}
}
namespace sub2 {
const int N = 3e2 + 5;
int dp[N][N][N];
void solve() {
dp[1][1][1] = 1;
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= min(i, k); j++) {
for (int pos = 1; pos <= i; pos++) {
add(dp[i][j][pos], dp[i - 1][j][pos - 1]);
add(dp[i][j][pos], diff(dp[i - 1][j - 1][i - 1], dp[i - 1][j - 1][pos - 1]));
add(dp[i][j][pos], dp[i][j][pos - 1]);
}
}
}
cout << dp[n][k][n];
}
}
namespace sub3 {
const int N = 3e3 + 5;
int dp[N][N];
void solve() {
// dem so luong hoan vi co k-1 cap p[i] > p[i+1]
dp[1][0] = 1;
for (int i = 2; i <= n; i++) {
dp[i][0] = 1;
for (int j = 1; j < min(i, k); j++) {
add(dp[i][j], 1ll * dp[i - 1][j] * (j + 1) % mod);
add(dp[i][j], 1ll * dp[i - 1][j - 1] * (i - j) % mod);
}
}
cout << dp[n][k - 1];
}
}
namespace sub4 {
int dp[2][N];
void solve() {
dp[1][0] = 1;
for (int i = 2; i <= n; i++) {
int cur = i & 1, pre = cur ^ 1;
dp[cur][0] = 1;
for (int j = 1; j < min(i, k); j++) {
dp[cur][j] = 0;
add(dp[cur][j], 1ll * dp[pre][j] * (j + 1) % mod);
add(dp[cur][j], 1ll * dp[pre][j - 1] * (i - j) % mod);
}
}
cout << dp[n & 1][k - 1];
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
if (fopen(Task".inp", "r")) {
freopen(Task".inp", "r", stdin);
freopen(Task".out", "w", stdout);
}
cin >> n >> k;
// sub1::solve(); cout << '\n';
// sub2::solve(); cout << '\n';
// sub3::solve(); cout << '\n';
sub4::solve();
}
컴파일 시 표준 에러 (stderr) 메시지
asceticism.cpp: In function 'int main()':
asceticism.cpp:118:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
118 | freopen(Task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
asceticism.cpp:119:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
119 | freopen(Task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~| # | 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... |