HDU 4906 Our happy ending (like pressure DP)

Source: Internet
Author: User

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;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.