UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#204565#3616. 数矩阵drdilyor1001072ms48072kbC++1.4kb2024-06-02 10:47:062024-06-02 12:09:49

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
int a[15][15];
int n,m;
void solve(){
    int cnt=0;
    for(int i=0;i<(1<<(n*m));i++){
        for(int j=0;j<n*m;j++){
            a[j/m][j%m]=(i>>j)&1;
        }
        bool fl=1;
        for(int j=0;j<n;j++){
            int c=0;
            for(int k=0;k<m;k++)c+=a[j][k];
            if(!c)fl=0;
        }
        for(int j=0;j<m;j++){
            int c=0;
            for(int k=0;k<n;k++)c+=a[k][j];
            if(!c)fl=0;
        }
        if(fl)cnt++;
    }
    cout<<cnt<<"\n";
}
int fac[3000005],ifac[3000005];
int qkp(int b,int p){
    int r=1;
    while(p){
        if(p&1)(r*=b)%=mod;
        p/=2;
        (b*=b)%=mod;
    }
    return r;
}
int C(int n,int m){
    if(n<m)return 0;
    return fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
signed main(){
    cin>>n>>m;
    //if(n<=4&&m<=4){solve();return 0;}
    fac[0]=1;
    for(int i=1;i<=3000000;i++)fac[i]=fac[i-1]*i%mod;
    ifac[3000000]=qkp(fac[3000000],mod-2);
    for(int i=2999999;i>=0;i--){
        ifac[i]=ifac[i+1]*(i+1)%mod;
    }
    int res=0;
    for(int i=0;i<=m;i++){
        int coef=C(m,i)*qkp((qkp(2,m-i)-1+mod)%mod,n)%mod;
        if(i&1)res+=mod-coef;
        else res+=coef;
        res%=mod;
    }
    cout<<res;
    return 0;
}
//https://oeis.org/A183109

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 40ms
memory: 48068kb

input:

4 4

output:

41503

result:

ok single line: '41503'

Test #2:

score: 10
Accepted
time: 31ms
memory: 48068kb

input:

3 4

output:

2161

result:

ok single line: '2161'

Test #3:

score: 10
Accepted
time: 29ms
memory: 48072kb

input:

500 500

output:

85182935

result:

ok single line: '85182935'

Test #4:

score: 10
Accepted
time: 36ms
memory: 48068kb

input:

499 498

output:

707477463

result:

ok single line: '707477463'

Test #5:

score: 10
Accepted
time: 45ms
memory: 48072kb

input:

2998 3000

output:

212916787

result:

ok single line: '212916787'

Test #6:

score: 10
Accepted
time: 41ms
memory: 48072kb

input:

3000 2999

output:

515587135

result:

ok single line: '515587135'

Test #7:

score: 10
Accepted
time: 297ms
memory: 48072kb

input:

1000000 1000000

output:

553135756

result:

ok single line: '553135756'

Test #8:

score: 10
Accepted
time: 272ms
memory: 48072kb

input:

999999 999998

output:

968547904

result:

ok single line: '968547904'

Test #9:

score: 10
Accepted
time: 39ms
memory: 48072kb

input:

1000000 12345

output:

459874263

result:

ok single line: '459874263'

Test #10:

score: 10
Accepted
time: 242ms
memory: 48068kb

input:

99998 1000000

output:

117334445

result:

ok single line: '117334445'

Extra Test:

score: 0
Extra Test Passed