题面:
题意:
给定 n 个 n 维随机 0/1 向量,求这 n 个 n 维随机 0/1 向量组成的矩阵满秩的概率。
题解:
对于每一个长度为 n 的向量,都有 2n 种情况,因为要求 n 个向量线性独立,所以我们依次讨论:
对于第一个向量来说,只需要至少有一个位置为 1 即可,即全部为 0 的情况不满足条件,此时满足条件的情况为 2n−1
对于第二个向量来说,需要满足的条件是,不能全部为 0 ,且不能被第一个向量所表示,此时满足条件的情况为 2n−2
对于第三个向量来说,同样不能为 0 ,不能被第一个向量所表示,不能被第二个向量所表示,不能被第一个向量和第二个向量所表示,此时满足条件的情况为 2n−4
对于第四个向量来说,不能被前面向量表示的集合为 { ∅ , { 1 } , { 2 } , { 3 } , { 1 , 2 } , { 1 , 3 } , { 2 , 3 } , { 1 , 2 , 3 } } ,共八种情况,所以此时满足条件的情况为 2n−8
…
对于第 n 个向量来说,不能被前面 n - 1 个向量单独或混合表示,此时满足条件的情况为 2n−2n−1
有 f[n]=∏i=0n−12n2n−2i
可以得到公式 f[n]=f[n−1]∗2n2n−1
代码:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<list>
#include<ctime>
#define ui unsigned int
#define ll long long
#define llu unsigned ll
#define ld long double
#define pr make_pair
#define pb push_back
#define lc (cnt<<1)
#define rc (cnt<<1|1)
#define len(x) (t[(x)].r-t[(x)].l+1)
#define tmid ((l+r)>>1)
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))
using namespace std;
const int inf=0x3f3f3f3f;
const ll lnf=0x3f3f3f3f3f3f3f3f;
const double dnf=1e18;
const int mod=1e9+7;
const double eps=1e-1;
const double pi=acos(-1.0);
const int hp=13331;
const int maxn=20000100;
const int maxp=400100;
const int maxm=600100;
const int up=200000;
int f[maxn];
ll mypow(ll a,ll b)
{
a%=mod,b%=(mod-1);
ll ans=1;
while(b)
{
if(b&1) ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
int main(void)
{
ll pow2=2,inv2=mypow(2,mod-2);
ll inv=inv2;
f[1]=inv2;
for(int i=2;i<maxn;i++)
{
pow2=pow2*2%mod;
inv2=inv2*inv%mod;
f[i]=f[i-1]*(pow2-1+mod)%mod*inv2%mod;
f[i-1]^=f[i-2];
}
int tt;
scanf("%d",&tt);
while(tt--)
{
int n;
scanf("%d",&n);
printf("%d\n",f[n]);
}
return 0;
}