HDU - 6285 Vertex Cover(构造)

Alice and Bobo are playing a game on a graph with nn vertices numbered with 0,1,…,(n−1)0,1,…,(n−1). 
The vertex numbered with ii is associated with weight 2i2i. 

The game is played as follows. 
Firstly, Alice chooses a (possibly empty) subset of the n(n−1)2n(n−1)2 edges. 
Subsequently Bobo chooses a (possibly empty) subset of the nn vertices to *cover* the edges chosen by Alice. 
An edge is *covered* if one of its two ends is chosen by Bobo. 
As Bobo is smart, he will choose a subset of vertices whose sum of weights, denoted as SS, is minimum. 

Alice would like to know the number of subsets of edges where Bobo will choose a subset whose sum of weights is exactly kk (i.e. S=kS=k), modulo (109+7)(109+7). 

Input

The input consists of several test cases and is terminated by end-of-file. 

Each test case contains two integers nn and kk. 
For convenience, the number kk is given in its binary notation. 

Output

For each test case, print an integer which denotes the result. 

## Constraint 

* 1≤n≤1051≤n≤105 
* 0≤k<2n0≤k<2n 
* The sum of nn does not exceed 250,000250,000. 

Sample Input

3 1
4 101
10 101010101

Sample Output

3
12
239344570

题意:有一个n个顶点的完全图,第i个顶点的权值为2^i,Alice选了一个边集,Bob会选择一个权值最小的点集,使得Alice的集合中任意一条边的两个顶点至少有个一被覆盖,先给出Bob选的点集,问Alice有多少种选法

思路:每个被选点至少要和一个权值比他大的非被选点连边,和权值比他小的点可连可不连

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;
const int M = 1e6 + 7;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

ll f[N];

int main() {
    f[0] = 1;
    for(int i = 1; i < N; ++i) f[i] = f[i - 1] * 2 % mod;
    int n;
    while(~scanf("%d", &n)) {
        string s;
        cin >> s;
        int siz = s.size();
        ll ans = 1, las = n - siz;
        for(int i = 0; i < siz; ++i) {
            if(s[i] == '1') {
                ans = ans * (f[las] - 1 + mod) % mod * f[siz - i - 1] % mod;
            }
            else las++;
        }
        printf("%lld\n", ans);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值