zoukankan      html  css  js  c++  java
  • [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;
    }
    
  • 相关阅读:
    python_网络编程struct模块解决黏包问题
    python_网络编程socket(UDP)
    python_网络编程socket(TCP)
    python_面向对象
    python_生成器
    python_迭代器
    linux实操_shell自定义函数
    linux实操_shell系统函数
    linux实操_shell读取控制台输入
    scrapy-redis 0.6.8 配置信息
  • 原文地址:https://www.cnblogs.com/wxjor/p/9573169.html
Copyright © 2011-2022 走看看