Description

给定$n$个数和$b$个盒子,放一些数到盒子中,使得盒子不为空。每个盒子中的数是一样的,一个数可以被放到多个盒子中。

从每个盒子中取一个数,组成一个$b$位数,如果这个数$mod\;k=x$,则这是一种合法的方案。求方案数$mod\;10^9+7$。

Input

第一行为$4$个数$n,b,x,k$。

Output

一行,表示方案数$mod 10^9+7$。

Sample Input

3 2 1 2
3 1 2

Sample Output

6

HINT

$2\;\leq\;n\;\leq\;50000,1\;\leq\;b\;\leq\;10^9,0\;\leq\;k\;\leq\;100, x\;\geq\;2,1\;\leq\;a_i\;\leq\;9$

Solution

显然序列中有用的条件仅有每个数出现的次数,记为$t[\;]$。

$f[i][j]$表示前$i$位数$mod\;k$的值为$j$的方案数。

$f[i+1][(j\;\times\;10+l)mod\;n]=f[i][j]\;\times\;t[l]$。

矩乘优化$DP$就能过了。

 #include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<cstdio>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define lld I64d
#define K 15
#define N 105
#define M 1000000007
using namespace std;
typedef long long ll;
struct matrix{
ll a[N][N];int n,m;
}a,b;
ll t[K];
int n,m,k,x;
inline matrix mult(matrix a,matrix b){
matrix c;c.n=a.n;c.m=b.m;
for(int i=;i<c.n;++i)
for(int j=;j<c.m;++j){
c.a[i][j]=;
for(int k=;k<a.m;++k)
c.a[i][j]=(c.a[i][j]+a.a[i][k]*b.a[k][j])%M;
}
return c;
}
inline matrix po(matrix a,int k){
matrix c;c.n=a.n;c.m=a.m;
for(int i=;i<a.n;++i)
for(int j=;j<b.n;++j)
if(i!=j) c.a[i][j]=;
else c.a[i][j]=;
while(k){
if(k&) c=mult(c,a);
a=mult(a,a);k>>=;
}
return c;
}
inline void init(){
scanf("%d%d%d%d",&n,&m,&x,&k);
for(int i=,j;i<=n;++i){
scanf("%d",&j);++t[j];
}
a.n=k;a.m=;
for(int i=;i<=;++i)
a.a[i%k][]+=t[i];
b.n=b.m=k;
for(int i=,l;i<k;++i){
for(int j=;j<=;++j){
l=(i*+j)%k;
b.a[l][i]+=t[j];
}
}
matrix c=mult(po(b,m-),a);
printf("%lld\n",c.a[x][]);
}
int main(){
freopen("blocks.in","r",stdin);
freopen("blocks.out","w",stdout);
init();
fclose(stdin);
fclose(stdout);
return ;
}

[cf621E]Wet Shark and Blocks的更多相关文章

  1. Codeforces Round #341 (Div. 2) E. Wet Shark and Blocks dp+矩阵加速

    题目链接: http://codeforces.com/problemset/problem/621/E E. Wet Shark and Blocks time limit per test2 se ...

  2. 【矩阵乘法优化dp】[Codeforces 621E] Wet Shark and Blocks

    http://codeforces.com/problemset/problem/621/E E. Wet Shark and Blocks time limit per test 2 seconds ...

  3. CODEFORCEs 621E. Wet Shark and Blocks

    E. Wet Shark and Blocks time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  4. 【38.24%】【codeforces 621E】 Wet Shark and Blocks

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. Codeforces Round #341 (Div. 2) E - Wet Shark and Blocks

    题目大意:有m (m<=1e9) 个相同的块,每个块里边有n个数,每个数的范围是1-9,从每个块里边取出来一个数组成一个数,让你求组成的方案中 被x取模后,值为k的方案数.(1<=k< ...

  6. cf 621E. Wet Shark and Blocks

    神奇,矩阵乘法23333333333333333 递推式是很简单的(连我这种不会DP的人都写出来了.) 需要求出的是转移矩阵(还是叫系数矩阵的),也是最这个东西用快速幂. 这个东西的i,j大概就表示从 ...

  7. 【CodeForces 621A】Wet Shark and Odd and Even

    题 Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wan ...

  8. 【CodeForces 621C】Wet Shark and Flowers

    题 There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such tha ...

  9. Wet Shark and Flowers(思维)

    C. Wet Shark and Flowers time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

随机推荐

  1. Mysql连接错误:Lost connection to Mysql server at 'waiting for initial communication packet'

    在远程连接mysql的时候,连接不上,出现如下报错:Lost connection to MySQL server at 'waiting for initial communication pack ...

  2. VS2010/VS2013怎么复制项目/拷贝项目/克隆项目

    本文以vs2013为例,讲述了如何复制项目.vs2008,vs2010,vs2012等版本应操作类似 vs中的项目位于解决方案中,简单的复制粘贴是不能实现项目复制的 一.准备 原项目名称:test 目 ...

  3. QT 数据库编程一

    QT如果要进行网络编程首先需要在.pro中添加如下代码:QT += network //logindlg.h #ifndef LOGINDLG_H #define LOGINDLG_H #includ ...

  4. “Word自动更改后的内容保存到通用文档模板上。是否加载该模板?“的解决办法

    在win7系统下,Word2010出现了不能正常关闭.打开一个已有word文档,点击右上角关闭按钮后,先提示"word已停止工作,windows正在检查该问题的解决方案",随后提示 ...

  5. Android反编译工具的使用-Android Killer

    今天百度搜索“Android反编译”搜索出来的结果大多数都是比较传统的教程.刚接触反编译的时候,我也是从这些教程慢慢学起的.在后来的学习过程中,我接触到比较方便操作的Android反编译.在这,我将使 ...

  6. ionic —— 开发环境搭建并编译运行第一个APP

    其实类似的环境已经玩了很多次了,最开始玩还是微信刚刚出来,那会儿没有智能机.只好安装一个模拟器,却只是为了注册一个微信.想想也就是够了~ 前前后后折腾了很多次,可是每一次都给人不一样的感觉,也许是这个 ...

  7. Sentinel-Redis高可用方案(二):主从切换

    Redis 2.8版开始正式提供名为Sentinel的主从切换方案,Sentinel用于管理多个Redis服务器实例,主要负责三个方面的任务:     1. 监控(Monitoring): Senti ...

  8. 【AHOI2014复仇】

    RT,NOIP全挂,屌丝要逆袭……原本准备在QQ空间写,结果发现打不开,然后发现了这个……

  9. MATLAB中白噪声的WGN和AWGN函数的使用

    MATLAB中白噪声的WGN和AWGN函数的使用如下: MATLAB中产生高斯白噪声非常方便,可以直接应用两个函数,一个是WGN,另一个是AWGN.WGN用于产生高斯白噪声,AWGN则用于在某一 信号 ...

  10. android之远程启动服务

    启动远程服务和隐式启动Activity一样 实现一个服务 为了演示方便,该服务是一个空服务 package xidian.dy.com.chujia; import android.app.Servi ...