zoukankan      html  css  js  c++  java
  • SRM 605 div 2 T3

    #include <bits/stdc++.h>
    #define Mo 1000000007
    #define MAXN 50
    #define MAXK 10
    using namespace std;
    int dp[2*MAXN+2][1<<MAXK];
    class AlienAndSetDiv2 {
    public:
        int N, K;
        int calc(int n, int unmatched)
        {
            int res = 0;
            if (-1 != dp[n][unmatched]) {
                return dp[n][unmatched];
            }
     
            if (n == 2 * N + 1) {
                if (0 == unmatched) {
                    res = 1;
                }
            } else {
                if (0 == unmatched) {
                    res += ( 2 * calc(n + 1, 1) ) % Mo;
                } else {
                    int newset = unmatched;
                    int i = 0;
                    for (i = 0; (newset & 0x80000000 ) == 0; newset = ( newset << 1 ), ++i) {
                    }
                    int mx = 31 - i;
                    res += calc(n + 1,  (unmatched - (1 << mx)) << 1 );    
                    res %= Mo;
     
                    if (mx != K - 1) {
                        newset = unmatched;
                        newset = ( (newset << 1) | 1 );
                        res += calc(n + 1, newset);
                        res %= Mo;
                    }
                }    
            }
            dp[n][unmatched] = res;
            return res;
        }
  • 相关阅读:
    windown reids
    redis 类型、方法
    nginx 路由配置
    http status code
    beego orm mysql
    thinkphp5
    beego
    MAC 更新brew 镜像源
    php session存入redis
    ios项目开发— iOS8 定位功能API改变
  • 原文地址:https://www.cnblogs.com/wjnclln/p/9571318.html
Copyright © 2011-2022 走看看