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 
  • 相关阅读:
    假期第六周总结
    假期第五周周总结
    navicat 链接oracle时出现的各种问题
    oracle 12如何解锁账户锁定状态及修改忘记的密码
    假期第四周周总结
    假期第三周周总结
    idea中使用git【推送,拉取,分支合并,解决冲突】
    Git分支,合并,切换分支的使用
    Git使用
    SpringCloud服务降级案列
  • 原文地址:https://www.cnblogs.com/JSZX11556/p/5045188.html
Copyright © 2011-2022 走看看