Hdu 4906 our happy ending

Source: Internet
Author: User

Our happy ending

Time limit:6000/3000 MS (java/others) Memory limit:131072/131072 K (java/others)
Total submission (s): 157 Accepted Submission (s): 39


Problem Descriptionthere is an old country and the king fell in love with a devil. The devil always asks the king to do some crazy things. Although the king used to is wise and beloved by his people. Now he's just like a boy in love and can ' t refuse any request from the devil. Also, this devil was looking like a very cute Loli.

Y*wan still remember the day he first meets the devil. Now everything was done and the devil is gone. Y*wan feel very sad and suicide.

You feel guilty after killing so many Loli, so you suicide too.

Nobody survive in this silly stories, but there are still some hope, because this was just a silly background story during one Programming contest!

And the last problem is:

Given a sequence a_1,a_2,..., A_n, if we can take some of them (each a_i can is only being used once), and they sum to K, then we Say this sequence is a good sequence.

How many good sequence is there? Given that each a_i are an integer and 0<= a_i <= L.

You should output the result modulo 10^9+7.

Inputthe first line contains an integer T, denoting the number of the the test cases.
For each test case, the first line contains 3 integers n, K, L.

t<=20, N,k<=20, 0<=l<=10^9.

Outputfor each cases, output the answer

Sample Input12 2 2

Sample OUTPUT6

Authorwjmzbmr

Source2014 multi-university Training Contest 4

It's sad to say it's a parting question,,,,

Delivery points should be sent when the penalty = =

It's a state DP bar.
Dp[i] represents the number of scenarios in the I state.

When I is binary, the first bit is 1 and the presence of 1 is present, 0 means no, the second bit is 1 and the existence of 2 is present.

When the third bit is 1, there is a and 3 exist ...
Transfer: STA = i| (1<< (k-1)) | (i<<j&m);
indicates that the state of I is transferred to the STA state
If the current state is 32 binary is 11, indicating that there is and for the existence of the,
if you add 3, then 3 of the state can be achieved, that is | ( 1<< (3-1))
There are 3 can be plus, that is, the original plus 3, that is, shift left 3 bits | ( I<<J) &m
because more than K and we do not care, so the largest state is (1<<k)-1;

#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <  cstring> #define MAXN 100010#define mod 1000000007#define LL long longusing namespace Std;int dp[(1<<20) +10]; int    Main () {int i, n,m,k,j;    int T, L;    Cin >> T;        while (t--) {scanf ("%d%d%d", &n,&k,&l);        Memset (Dp,0,sizeof (DP));        Dp[0]=1;        m = (1<<k)-1;        int tot = 0;            if (L > k) {tot = L-k;        L = k;                } while (n--) {for (i = m; I >= 0; i--) {if (dp[i]==0) continue;                j = Dp[i];                ll tmp = (ll) tot*dp[i]%mod; for (int u = 1; u <= L; u++) {int sta = (i| ( 1<< (u-1)) | ((i<<u) &m))                    ;                    Dp[sta] + = j;                Dp[sta]%= mod;            } Dp[i] = (dp[i]+tmp)%mod;}} LL ans = 0;        for (i = 0; I <= m; i++) if ((I>> (k-1)) &1) {ans = (ans+dp[i])%mod;    } cout << ans << endl; } return 0;}

Related Article

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.