Editorial for Bedao Grand Contest 03 - DIARR
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Code mẫu
#include <bits/stdc++.h> using namespace std; const int N = 505, K = 505, MOD = 1E9 + 7; int n, k, a[N], dp[N][K]; long long ans = 0; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); freopen("DIARR.inp", "r", stdin); freopen("DIARR.out", "w", stdout); cin >> n >> k; if (k == 1) { return cout << 0, 0; } for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + n + 1); dp[0][0] = 1; for (int mi = 1; mi <= a[n] / (k - 1); mi++) { for (int i = 1, pt = 1; i <= n; i++) { fill(dp[i], dp[i] + k + 1, 0); for (; pt < i && a[i] - a[pt] >= mi; pt++); for (int j = 1; j <= k; j++) { (dp[i][j] += dp[pt - 1][j - 1]) %= MOD; } for (int j = 0; j <= k; j++) { (dp[i][j] += dp[i - 1][j]) %= MOD; } } (ans += dp[n][k]) %= MOD; } cout << ans; }
Comments