题目链接:点击查看
题目大意:给出一个 n * n 的 01 矩阵,求满秩的概率
题目分析:首先公式是:
稍微解释一下吧,将 n * n 的矩阵视为 n 个长度为 n 的向量,对于每一个长度为 n 的向量,都有 2^n 种情况,因为要求 n 个向量线性独立,所以我们依次讨论:
- 对于第一个向量来说,只需要至少有一个位置为 1 即可,即全部为 0 的情况不满足条件,此时满足条件的情况为
- 对于第二个向量来说,需要满足的条件是,不能全部为 0 ,且不能被第一个向量所表示,此时满足条件的情况为
- 对于第三个向量来说,同样不能为 0 ,不能被第一个向量所表示,不能被第二个向量所表示,不能被第一个向量和第二个向量所表示,此时满足条件的情况为
- 对于第四个向量来说,不能被前面向量表示的集合为 { ∅ , { 1 } , { 2 } , { 3 } , { 1 , 2 } , { 1 , 3 } , { 2 , 3 } , { 1 , 2 , 3 } } ,共八种情况,所以此时满足条件的情况为
- ......
- 对于第 n 个向量来说,不能被前面 n - 1 个向量单独或混合表示,此时满足条件的情况为
然后下一步就是将其转换为递推式,根据
实现的话递推 2 的逆元就好了,在 mod 为 1e9+7 时,2 的逆元为 500000004
代码:
#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<sstream>
#include<cassert>
#include<bitset>
#include<unordered_map>
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int N=2e7+100;
const int mod=1e9+7;
LL f[N],inv=500000004,ans[N];
void init()
{
ans[1]=f[1]=500000004;
LL _2=4,inv_2=inv*inv%mod;
for(int i=2;i<N;i++)
{
f[i]=f[i-1]*(_2-1)%mod*inv_2%mod;
_2=_2*2%mod;
inv_2=inv_2*inv%mod;
ans[i]=ans[i-1]^f[i];
}
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("data.in.txt","r",stdin);
// freopen("data.out.txt","w",stdout);
#endif
// ios::sync_with_stdio(false);
init();
int w;
cin>>w;
while(w--)
{
int n;
scanf("%d",&n);
printf("%lld\n",ans[n]);
}
return 0;
}