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 
  • 相关阅读:
    Android Activity 四种启动模式
    Android Activity的生命周期
    Android SQLite (五 ) 全面详解(三)
    Android SQLite (四 ) 全面详解(二)
    工作流设计 zt
    法律网站分类 ­zt
    刑事案件的构成要素 zt
    犯罪构成三层次记忆口诀 zt
    E asy Boo t 6.51 启动易 制作启动光盘的软件(附注册码)
    父线程开启子进程且共享内存
  • 原文地址:https://www.cnblogs.com/JSZX11556/p/5045188.html
Copyright © 2011-2022 走看看