QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#65768#4843. Infectious DiseaseKaibadCompile Error//C++141.3kb2022-12-03 16:42:272022-12-03 16:42:31

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-03 16:42:31]
  • 评测
  • [2022-12-03 16:42:27]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long

int n,p[14000005]={1},dp[16][16385];
int ny[14000005];
const int mod=1e9+7;

int qpow(int a,int b){
    int ans=1;
    while(b){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}

int inv(int x){
	return qpow(x,mod-2);
}

int c(int n,int m){
	if(m>n) return 0;
	return (p[n]*ny[m]%mod)*ny[n-m]%mod;
}

void solve(){
	cin>>n;
	dp[0][1]=1;
	for(int i=1;i<=14000000;i++) p[i]=p[i-1]*i%mod;
	ny[14000000]=qpow(p[14000000],mod-2);
	for(int i=14000000-1;i>=0;i--){
		ny[i]=(ny[i+1]*(i+1))%mod;
	}
	for(int i=1;i<=15;i++){
		int sheng=n-qpow(3,i-1),xuan=qpow(3,i)-qpow(3,i-1);
		if(sheng<=xuan){
			for(int j=1;j<=(1<<(i-1));j++){
				dp[i][0]=(dp[i][0]+dp[i-1][j])%mod;
			}
			break;
		}
		int all=inv(c(sheng,xuan));
		for(int j=0;j<=(1<<i);j++){
			for(int k=max(1ll,(j+1)>>1);k<=(1<<(i-1));k++){
				int gan=2*k-j;
				dp[i][j]=(dp[i][j]+dp[i-1][k]*c(2*k,gan)%mod*c(sheng-2*k,xuan-gan)%mod*all)%mod;
			}
		}
	}
	int ans=0;
	for(int i=1;i<=15;i++) ans=(ans+dp[i][0]*i)%mod;
	cout<<ans;
}

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int T=1;/*
	cin>>T;//*/
	while(T--) solve();
	return 0;
}


詳細信息

Compiler Output Limit Exceeded