Bzoj2839: Set Count: Combinatorial mathematics + __bzoj

Source: Internet
Author: User

Topic Link: Collection Count

The answer is to contain at least K-at least k+1 + at least k+2 ...

Select K as the number of the intersection from N number, is C (n,k), such a set of total 2^ (2^ (n-k))-1

2^ (N-K) is the number of optional sets containing the selected K number, and the selection scheme has 2^ (2^ (n-k))-1 (cannot have an empty set or cannot guarantee k elements)

therefore Ans=c (n,k) *c (k,k) * (2^ (2^ (n-k))-1)-C (n,k+1) *c (k+1,k) *2^ (2^) (n-k-1)

No linear negation is really slow death ...

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define LL Long-long
using namespace std;
const int mod=1000000007;
const int maxn=1000010;
int fac[maxn],inv[maxn],n,k;
ll Ans=0;

int quick_pow_mod (int x,int y,int mod) {
	int ret=1;
	while (y) {
		if (y&1) ret=1ll*ret*x%mod;
		X=1ll*x*x%mod; y>>=1;
	} return ret;

ll C (int n,int m) {return

ll calc (int x) {return
	C (n,x) *c (x,k)%mod* (Quick_pow_mod (2,quick_pow_mod (2,n-x,mod-1), MoD)-1)%mod;

int main () {
	scanf ("%d%d", &n,&k);
	for (int i=1;i<=n;++i) fac[i]=1ll*fac[i-1]*i%mod;
	for (int i=0;i<=n;++i) inv[i]=quick_pow_mod (fac[i],mod-2,mod);
	int cur=1;
	for (int i=k;i<=n;++i) {
		ans+=cur*calc (i);
		if (ans>=mod) ans-=mod;
		else if (ans<=-mod) ans+=mod;
	printf ("%lld", (ans+mod)%mod);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.