• [Arc058E] Iroha and Haiku


    [Arc058E] Iroha and Haiku

    题目大意

    问有多少(n)个数的正整数序列,每个数在([1,10])之间,满足存在(x,y,z,w)使得(x o y-1,y o z-1,z o w)的和分别为(X,Y,Z)
    (X,Zleq 5,Yleq 7)

    试题分析

    由于发现(X+Y+Z)(a_i)很小,所以考虑状态压缩,可以用位数来表示数字,比如(5=10000,1=1)
    然后不合法方案数比合法方案数好求,所以直接求不和法即可。

    #include<iostream>
    #include<cstring>
    #include<vector>
    #include<queue>
    #include<cstdio>
    #include<algorithm>
    using namespace std;
     
    #define LL long long
     
    inline LL read(){
    	LL x=0,f=1;char c=getchar();
    	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
    	return x*f;
    }
    const LL INF=9999999;
    const LL MAXN=100010;
    const LL Mod = 1e9+7;
     
    LL N,X,Y,Z;
    LL Finall,MAX;
    LL f[41][(1<<18)];
    LL ans=0;
     
    int main(){
    	//freopen(".in","r",stdin);
    	//freopen(".out","w",stdout);
    	N=read(); X=read(),Y=read(),Z=read();
    	Finall=(1LL<<(X-1))|(1LL<<(X+Y-1))|(1LL<<(X+Y+Z-1));
    	MAX=(1LL<<(X+Y+Z))-1; f[0][0]=1; LL Pw=1;
    	for(LL i=0;i<N;i++){
    		Pw=Pw*10LL%Mod;
    		for(LL j=0;j<=MAX;j++){
    			if(!f[i][j]) continue;
    			for(LL k=1;k<=10;k++){
    				LL x=MAX&((j<<k)|(1LL<<(k-1)));
    				if((x&Finall)==Finall) continue;
    				f[i+1][x]+=f[i][j]; f[i+1][x]%=Mod;
    			} 
    		} //cout<<endl; system("pause");
    	} for(LL j=0;j<=MAX;j++) (ans+=f[N][j])%=Mod;
    	printf("%lld
    ",(Pw-ans+Mod)%Mod);
    	return 0;
    }
    
  • 相关阅读:
    IDEA提交项目到SVN
    动态代理
    eclipse安装svn,初次提交项目到svn
    异常信息:java.lang.IllegalStateException: Cannot forward after response has been committed
    网上商城订单
    学生选课系统
    分页
    用户注册登录 和 数据写入文件的注册登录
    第一次考试(基础部分)
    小数和质数问题
  • 原文地址:https://www.cnblogs.com/wxjor/p/9573169.html
Copyright © 2020-2023  润新知