HDU 4906 our happy ending
Topic links
Test instructions: Given n numbers, each number can be 0-l, select some of the numbers, and then make and K, ask the scheme
Idea: A pressure DP, a scrolling array, a state that represents the number of I, a state that can consist of a number state of S, and then one number at a time, the loop enumerates how much it wants to select 1-min (l,k), then the state transitions
Code:
#include <cstdio> #include <cstring>typedef long long ll;const int N = (1<<20) + 5;const ll MOD = 1000000 007;int T, N, K;ll L, dp[n];int Main () { scanf ("%d", &t); while (t--) {scanf ("%d%d%lld", &n, &k, &l); int s = (1<<k); ll yu = L-k;l = K;memset (DP, 0, sizeof (DP)); Dp[0] = 1;while (n--) {for (int i = s-1, i >= 0; i--) {if (dp[i] = = 0) continue;ll tmp = Yu * dp[i]% Mod;ll now = dp[i];for (int j = 1; J <= L; j + +) { int next = i| ( (i<<j) & (s-1) | (1<< (j-1))); Dp[next] = (Dp[next] + now)% MOD;} Dp[i] = (Dp[i] + tmp)% MOD; }} ll ans = 0;for (int i = 0; i < s; i++) { if (i& (1<< (k-1))) {ans = (ans + dp[i])% MOD; } printf ("%lld\n", ans); } return 0;}