# 集合计数

#### 样例输入

3 2

#### 样例输出

6

#### 数据说明

$f[i]=C(n,i)*(2{^{2^{n-i}}}-1)$

ABC    D==ACD     B==ABD     C==BCD      A

同理f[k+2]:+C(k+2，k+1)*C(k+1，k)==C(k+2，k)

for(ll i=k;i<=n;i++)
ans=(C(i,k)*f[i]%p*((i-k)&1?-1:1)+ans)%p;

    ni[n]=meng(jie[n],p-2);
for(ll i=n-1;i>=1;i--)ni[i]=ni[i+1]*(i+1)%p;

：for(ll i=1;i<=maxn;i++) ermi[i]=2*ermi[i-1]%(p-1);//2^ermi[i]%p!=2^ermi[i]%p调两节课

：for(ll i=0;i<=n;i++)又一节半课，实在是菜

：ermi[0]又二十分钟，

首先关于为什么mod (p-1)而不是mod (p)

$2^{φ(p)} mod p$同余于1，${2^i}==kφ(p)+t$t就等于$2^i mod φ(p)$，又φ(质数)==p-1

 1 #include<bits/stdc++.h>
2 #define ll long long
3 #define A 1100000
4 #define maxn 1000010
5 #define p 1000000007
6 using namespace std;
7 ll m,n,k,f[A],jie[A],ermi[A],ans,ni[A];
9 {
10     ll f=1,x=0;char c=getchar();
11     while(!isdigit(c)){if(c=='-') f=-1;c=getchar();}
12     while(isdigit(c)){x=(x<<1)+(x<<3)+c-'0';c=getchar();}
13     return f*x;
14 }
15 ll meng(ll x,ll k)
16 {
17     ll ans=1;
18     for(;k;k>>=1,x=x*x%p)
19         if(k&1)
20             ans=x%p*ans%p;
21     return ans;
22 }
23 ll C(ll n,ll m)
24 {
25     if(m==0) return 1;
26     if(m>n) return 0;
27     else return (jie[n]*ni[m]%p*ni[n-m])%p;
28 }
29 void init()
30 {
32     m=n-k;
33     jie[0]=1;ni[0]=1;ermi[0]=1;
34     for(ll i=1;i<=maxn;i++)    ermi[i]=2*ermi[i-1]%(p-1);//2^ermi[i]%p!=2^ermi[i]%p
35     for(ll i=1;i<=n;i++)    jie[i]=jie[i-1]*i%p;
36     ni[n]=meng(jie[n],p-2);
37     for(ll i=n-1;i>=1;i--)ni[i]=ni[i+1]*(i+1)%p;
38     for(ll i=0;i<=n;i++)    f[i]=C(n,i)%p*(meng(2,ermi[n-i])%p-1)%p;
39 }
40 int main()
41 {
42 //    freopen("test.in","r",stdin);freopen("vio.out","w",stdout);
43     ans=0;
44     init();
45     for(ll i=k;i<=n;i++)
46     ans=(C(i,k)*f[i]%p*((i-k)&1?-1:1)+ans)%p;
47     cout<<(ans%p+p)%p<<endl;
48 }
View Code

 1 #include<bits/stdc++.h>
2 int main()
3 {
4     while(true)
5     {
6         system("./mkd"),puts("mkd runs out");
7         system("./std"),puts("std runs out");
8         system("./vio"),puts("vio runs out");
9         if(system("diff std.out vio.out")) while(true);
10         puts("");
11     }
12     return 0;
13 }
View Code

posted @ 2019-07-04 12:18  znsbc  阅读(174)  评论(0编辑  收藏  举报