Submission #363897

#TimeUsernameProblemLanguageResultExecution timeMemory
363897Kevin_Zhang_TWAsceticism (JOI18_asceticism)C++17
49 / 100
1046 ms492 KiB
#include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() {cerr << endl;}
template<class T, class ...U> void kout (T v, U ...e) { cerr << v << ' ', kout(e...); }
template<class T> void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L)==R], ++L; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
// What I should check
// 1. overflow
// 2. corner cases
// Enjoy the problem instead of hurrying to AC
// Good luck !
const int MAX_N = 100010, p = 1e9 + 7;

ll dp[MAX_N];

//void add(ll &a, ll b) { a += b - p, a += (a >> 63) & p; }

#pragma GCC optimize("Ofast")
#pragma GCC target("sse4", "avx2")

int32_t main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int n, k;
	cin >> n >> k;

	dp[0] = 1;

	for (int i = 2;i <= n;++i) {
		for (int j = min(k - 1, i - 1);j > 0;--j) {
			dp[j] = (dp[j] * (j + 1) + dp[j - 1] * (i - j)) % p;
		}
	}
	cout << dp[k - 1] << '\n';
//
//	// dp[i][j] =
//	// dp[i-1][j] * (j + 1)
//	// +
//	// dp[i-1][j-1] * (i - j)
//	//
//	for (int i = 2;i <= n;++i) {
//		for (int j = 0;j < i;++j)
//			dp[i][j] = (dp[i-1][j] * (j + 1) + 
//				(j ? dp[i-1][j-1] : 0) * (i - j)) % p;
//
////		for (int j = 0;j < i;++j) {
////			dp[i + 1][j] += dp[i][j] * (j + 1);
////			dp[i + 1][j + 1] += dp[i][j] * (i - j);
////		}
////
////			add(dp[i + 1][j], dp[i][j] * (j + 1) % p);
////			add(dp[i + 1][j + 1], dp[i][j] * (i + 1 - (j + 1)) % p);
//	}
//
	//cout << dp[n][k-1] << '\n';
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...