标签:base phrase hat ring format 定义 tis 数字 cpp
标签: 状态压缩DP
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,Z-Haiku (defined below) in integer sequences.
Consider all integer sequences of length N whose elements are between 1 and 10, inclusive. Out of those 10N sequences, how many contain an X,Y,Z-Haiku?
Here, an integer sequence a0,a1,…,aN?1 is said to contain an X,Y,Z-Haiku if and only if there exist four indices x,y,z,w(0≤x<y<z<w≤N) such that all of the following are satisfied:
ax+ax+1+…+ay?1=X
ay+ay+1+…+az?1=Y
az+az+1+…+aw?1=Z
Since the answer can be extremely large, print the number modulo 109+7.
3≤N≤40
1≤X≤5
1≤Y≤7
1≤Z≤5
The input is given from Standard Input in the following format:
N X Y Z
Print the number of the sequences that contain an X,Y,Z-Haiku, modulo 109+7.
3 5 7 5
1
Here, the only sequence that contains a 5,7,5-Haiku is [5,7,5].
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
int n,a,b,c;
ll dp[42][1<<17];
int main(int argc, char const *argv[])
{
scanf("%d%d%d%d", &n,&a,&b,&c);
dp[0][0]=1;
int base=(1<<(c-1))+(1<<(b+c-1))+(1<<(a+b+c-1));
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < (1<<(a+b+c)); ++j)
{
for (int k = 0; k < 10; ++k)
{
int x=(j<<(k+1))+(1<<k);
x&=((1<<(a+b+c))-1);
if((x&base)!=base){
dp[i+1][x]+=dp[i][j];
dp[i+1][x]%=MOD;
}
}
}
}
ll ans=1;
for (int i = 0; i < n; ++i)
{
ans=ans*10%MOD;
}
for (int i = 0; i < (1<<(a+b+c)); ++i)
{
ans=(ans-dp[n][i])%MOD;
}
ans=(ans+MOD)%MOD;
printf("%lld\n", ans);
return 0;
}
标签:base phrase hat ring format 定义 tis 数字 cpp
原文地址:https://www.cnblogs.com/sciorz/p/9058610.html