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;
    }

 

转载于:https://www.cnblogs.com/wjnclln/p/9571318.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值