HDU 4906 our happy ending
pid=4906 "style=" "> Topic Links
Test instructions: Given n numbers, each digit can be a 0-l, select some of the numbers. Then make and for K, ask the program
Idea: Pressure DP. Scrolls the array, indicating the number of the first I. Can compose the state of the number state as S, and then each time a number, loop enumerates how much it is to pick 1-min (l,k) and then make a state transition
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); if (L > 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;}
HDU 4906 Our happy ending (like pressure DP)