Vertex Cover 湘潭CCPC邀请赛 (递推)

链接:https://ac.nowcoder.com/acm/contest/1107/J
来源:牛客网
 

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32768K,其他语言65536K
Special Judge, 64bit IO Format: %lld

题目描述

Alice and Bobo are playing a game on a graph with n vertices numbered with 0,1,…,(n−1)0, 1, \dots, (n - 1)0,1,…,(n−1).
The vertex numbered with i is associated with weight 2i2^i2i.

The game is played as follows.
Firstly, Alice chooses a (possibly empty) subset of the n(n−1)2\frac{n(n - 1)}{2}2n(n−1)​ edges.
Subsequently Bobo chooses a (possibly empty) subset of the n 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 S, 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 k (i.e. S = k), modulo (109+7)(10^9+7)(109+7).

输入描述:

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

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

输出描述:

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

示例1

输入

复制

3 1
4 101
10 101010101

输出

复制

3
12
239344570

备注:

* 1≤n≤1051 \leq n \leq 10^51≤n≤105
* 0≤k<2n0 \leq k < 2^n0≤k<2n
* The sum of n does not exceed 250,000.

 

          假设这个点是1,则他只能和所有之前不是1的点相连(否则就不满足最小化覆盖的要求了),如果他是0,则他能和所有之前是1的点相连(否则的话也不满足全覆盖的要求)。

#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
#define ll long long
ll sum[100010];
int main() {
	sum[0] = 1; int n;
	for (int i = 1; i < 100010; i++)
		sum[i] = (sum[i - 1] * 2) % mod;
	string m; 
	while (cin >> n >> m) {
		ll res = 1; int len = m.length();
		int pre = n - len, la = 0;
		for (int i = 0; i < len; i++, pre++) {
			if (m[i] == '1') {
				res = res * (sum[pre] - sum[la++] + mod) % mod;
			}
			else {
				res = res * sum[la] % mod;
			}
		}
		cout << res << "\n";
	}
	return 0;
}
//1 2 3 4

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值