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. linux下截取给定路径中的目录部分

    在日常运维中,有时会要求截取一个路径中的目录部分.截取目录的方法,有以下两种:1)dirname命令(最常用的方法):用于取给定路径的目录部分.很少直接在shell命令行中使用,一般把它用在shell ...

  2. scrapy系统学习(1)--概要

    本文操作环境:ubuntu14.04 一.安装Scrapy/Mysql/MySQLdb 参照官网教程安装Scrapy #sudo apt-key adv --keyserver hkp://keyse ...

  3. js继承《转》

    http://www.jb51.net/article/55540.htm http://www.cnblogs.com/OceanHeaven/p/4965947.html http://www.j ...

  4. Pycharm: keyboard reference

    Source: Official set ♥ Editing Ctrl + Space Basic code completion (the name of any class, method or ...

  5. centos6下安装dedecms

    几经波折,终于安装成功!!! 一.centos6下安装WDCP 1.连接linux 在百度直接搜索下载xshell,通过ssh连接 2.安装wdcp 下载安装wget http://dl.wdlinu ...

  6. 使用spring boot+mybatis+mysql 构建RESTful Service

    开发目标 开发两个RESTful Service Method Url Description GET /article/findAll POST /article/insert 主要使用到的技术 j ...

  7. SQL Server 百万级数据提高查询速度的方法

    1.应尽量避免在 where 子句中使用!=或<>操作符,否则将引擎放弃使用索引而进行全表扫描. 2.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉 ...

  8. caffe的python接口学习(2):生成solver文件

    caffe在训练的时候,需要一些参数设置,我们一般将这些参数设置在一个叫solver.prototxt的文件里面,如下: base_lr: 0.001 display: 782 gamma: 0.1 ...

  9. Python2.3-原理之语句和语法

    此节来自于<Python学习手册第四版>第三部分 一.python语句简介(第10章) 1.首先记得一个概念:a.程序由模块构成:b.模块包含语句:c.语句包含表达式:d.表达式建立并处理 ...

  10. Scala入门详解

    object作为Scala中的一个关键字,相当于Java中的public static class这样的一个修饰符,也就说object中的成员都是静态的! 所以我们在这个例子中的main方法是静态的, ...