zoukankan      html  css  js  c++  java
  • BZOJ 3870: Our happy ending( 状压dp )

    dp(i, s)表示考虑了前i个数后, 能取到的数的集合为s时的方案数.对于1~min(L, K)枚举更新, 剩下的直接乘就好了. 复杂度O(T*K*2^N)。。。好像有点大, 但是可以AC。。。。

    ------------------------------------------------------------------------------

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
     
    using namespace std;
     
    typedef long long ll;
    #define b(i) (1 << (i))
     
    const int MOD = 1000000007;
     
    int N, g, L, dp[b(21)];
     
    inline void upd(int &x, int t) {
    if((x += t) >= MOD) x -= MOD;
    }
     
    int main() {
    int T;
    scanf("%d", &T);
    while(T--) {
    scanf("%d%d%d", &N, &g, &L);
    memset(dp, 0, sizeof dp);
    dp[1] = 1;
    int All = b(g + 1) - 1;
    while(N--) {
    for(int s = All; s; s--) if(dp[s]) {
    int t = dp[s];
    for(int i = min(g, L); i; i--)
    upd(dp[s | ((s << i) & All) | b(i)], t);
    if(L > g) upd(dp[s], ll(t) * (L - g) % MOD);
    }
    }
    int ans = 0;
    for(int i = All; i; i--)
    if(i & b(g)) upd(ans, dp[i]);
    printf("%d ", ans);
    }
    return 0;
    }

    ------------------------------------------------------------------------------

    3870: Our happy ending

    Time Limit: 10 Sec  Memory Limit: 256 MB
    Submit: 146  Solved: 84
    [Submit][Status][Discuss]

    Description

    There 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 be wise and beloved by his people. Now he is just like a boy in love and can’t refuse any request from the devil. Also, this devil is looking like a very cute Loli.
    Y*wan still remember the day he first meets the devil. Now everything is 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 story, but there is still some hope, because this is 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 only be used once), and they sum to k, then we say this sequence is a good sequence.
    How many good sequence are there? Given that each a_i is an integer and 0<= a_i <= L.
    You should output the result modulo 10^9+7.

    Input

    The first line contains an integer T, denoting the number of 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.

    Output

    For each cases, output the answer in a single line.

    Sample Input

    1
    2 2 2

    Sample Output

    6

    HINT

    Source

  • 相关阅读:
    项目风险软考之软工基础知识(1)
    序列输出ZOJ1108 FatMouse's Speed
    电平波特率UART自适应波特率的设置方法
    nullnull2013金山西山居创意游戏程序挑战赛——初赛(3)生日猜猜猜
    删除监听oracle单库彻底删除干净的方法
    类关闭由一个activity启动第二个activity
    代码文件android:向手机卡上写入文件时总是不成功,解决办法
    功能应用程序延迟发送:4款定时发送短信的应用程序
    监听事件android activity中键盘的监听
    nullnull爆笑百家讲坛之十大逆袭情侣.
  • 原文地址:https://www.cnblogs.com/JSZX11556/p/5175910.html
Copyright © 2011-2022 走看看