AtCoder Regular Contest 058--E - 和風いろはちゃん / Iroha and Haiku(转化01串+状态压缩)

E - 和風いろはちゃん / Iroha and Haiku


Time Limit: 4 sec / Memory Limit: 512 MB

Score : 700700 points

Problem Statement

Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.

Iroha is looking for X,Y,ZX,Y,Z-Haiku (defined below) in integer sequences.

Consider all integer sequences of length NN whose elements are between 11 and 1010, inclusive. Out of those 10N10N sequences, how many contain an X,Y,ZX,Y,Z-Haiku?

Here, an integer sequence a0,a1,...,aN−1a0,a1,...,aN−1 is said to contain an X,Y,ZX,Y,Z-Haiku if and only if there exist four indices x,y,z,w(0≦x<y<z<w≦N)x,y,z,w(0≦x<y<z<w≦N)such that all of the following are satisfied:

  • ax+ax+1+...+ay−1=Xax+ax+1+...+ay−1=X
  • ay+ay+1+...+az−1=Yay+ay+1+...+az−1=Y
  • az+az+1+...+aw−1=Zaz+az+1+...+aw−1=Z

Since the answer can be extremely large, print the number modulo 109+7109+7.

Constraints

  • 3≦N≦403≦N≦40
  • 1≦X≦51≦X≦5
  • 1≦Y≦71≦Y≦7
  • 1≦Z≦51≦Z≦5

Input

The input is given from Standard Input in the following format:

NN XX YY ZZ

Output

Print the number of the sequences that contain an X,Y,ZX,Y,Z-Haiku, modulo 109+7109+7.


Sample Input 1 Copy

Copy

3 5 7 5

Sample Output 1 

这个题完全没有思路......然后看了看题解也不是特别明白,讨论一下稍后再写一下。

大题解法是看做01串,1就是1,2 就是10,那么n就是1后面n-1个0,然后看后面的x+y+z位是否包含x+y+z,包含的话就是不符合情况的,统计这些。最后减去。

#include<cstdio>
#include<iostream>
using namespace std;
int n,x,y,z,nw;
const int mod=1e9+7;
int S,f[45][1<<17],ans=1;
int main()
{
    scanf("%d",&n);
    scanf("%d%d%d",&x,&y,&z);
    for (int i=1;i<=n;i++) ans=1ll*ans*10%mod;
    nw=(1<<x-1)|(1<<x+y-1)|(1<<x+y+z-1);
    S=(1<<x+y+z)-1;//---
    f[0][0]=1;//---
    for (int i=1;i<=n;i++)
        for (int j=0;j<=S;j++)
        {
            for (int k=1;k<=10;k++)
            {
                int T=(j<<k)|(1<<k-1);
                T&=S;
                if ((T&nw)!=nw) f[i][T]=(f[i][T]+f[i-1][j])%mod;
            }
        }
    for (int i=0;i<=S;i++) ans=(ans-f[n][i]+mod)%mod;
    printf("%d",ans);
} 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值