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 
  • 相关阅读:
    Spring AOP应用场景你还不知道?这篇一定要看!
    解决 Failed to start LSB: Bring up/down networking 问题
    查出undefined symbol项命令
    将当前目录加入库环境变量
    Fortran代码生成so库
    Java调用Fortran生成so库报“libifport.so.5: 无法打开共享对象文件”错误解决方法
    HBase过滤器(转载)
    HBase设计规范(转载)
    spark(2.1.0) 操作hbase(1.0.2)
    zookeeper搭建
  • 原文地址:https://www.cnblogs.com/JSZX11556/p/5045188.html
Copyright © 2011-2022 走看看