zoukankan      html  css  js  c++  java
  • SGU 310. Hippopotamus( 状压dp )

    题目大意:给N块板, 有A,B2种类型的板, 要求任意M块连续的板中至少有K块B板.1≤n≤60,1≤m≤15,0≤k≤m≤n.

    dp(x, s)表示第x块板, x前M块板的状态为s, 然后合法状态转移就行了. 

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

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
     
    using namespace std;
     
    typedef long long ll;
     
    const int maxn = 61;
    const int maxm = 21;
     
    #define b(x) (1 << (x))
     
    int N, M, K, cnt[b(maxm)];
    ll dp[2][b(maxm)];
     
    int main() {
    scanf("%d%d%d", &N, &M, &K);
    int c = 0, p = 1;
    for(int s = b(M); s--; ) {
    cnt[s] = 0;
    for(int i = 0; i < M; i++)
    if(s & b(i)) cnt[s]++;
    dp[c][s] = (cnt[s] >= K);
    }
    int t = b(M - 1);
    for(int i = N - M; i--; ) {
    swap(c, p);
    memset(dp[c], 0, sizeof dp[c]);
    for(int s = b(M); s--; ) if(cnt[s >> 1] >= K) {
    dp[c][s >> 1] += dp[p][s];
    dp[c][s >> 1 | t] += dp[p][s];
    } else if(cnt[s >> 1] + 1 == K)
    dp[c][s >> 1 | t] += dp[p][s];
    }
    ll ans = 0;
    for(int i = b(M); i--; )
    if(cnt[i] >= K) ans += dp[c][i];
    printf("%lld ", ans);
    return 0;
    }

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

    310. Hippopotamus

    Time limit per test: 0.5 second(s)
    Memory limit: 65536 kilobytes
    input: standard
    output: standard



    After fixing your roof, you still think that it looks unpretty. So you opt for a new one, consisting of n consecutive long narrow boards. You have two types of boards: wooden ones and iron ones, giving you an amazing total of 2n possible roofs.

    But the safety should not be left aside. Having considered the weight and the cruising speed of a falling hippopotamus, you decide to have at least k iron boards among every m consecutive boards.

    How many possibilities do you have?

    Input
    The input file contains three integers, nm and k, separated by spaces and/or line breaks. 1 ≤ n ≤ 60, 1 ≤ m ≤ 15, 0 ≤ k ≤ m ≤ n.

    Output
    Output the number of possibilities.

    Example(s)
    sample input
    sample output
    10 2 1 
    144 

    sample input
    sample output
    5 5 2 
    26 

    sample input
    sample output
    3 2 2 
    1 
  • 相关阅读:
    pyhanlp 实体命名识别
    NABCD需求分析
    源代码
    遇到的问题和解决方法
    运行及总结
    测试与调试
    读《一个程序猿的生命周期》和《人,绩效和职业道德》有感
    面向对象程序设计
    设计类图
    SRS文档
  • 原文地址:https://www.cnblogs.com/JSZX11556/p/5045188.html
Copyright © 2011-2022 走看看