[cf621E]Wet Shark and Blocks
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的更多相关文章
- 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 ...
- 【矩阵乘法优化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 ...
- 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 ...
- 【38.24%】【codeforces 621E】 Wet Shark and Blocks
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Codeforces Round #341 (Div. 2) E - Wet Shark and Blocks
题目大意:有m (m<=1e9) 个相同的块,每个块里边有n个数,每个数的范围是1-9,从每个块里边取出来一个数组成一个数,让你求组成的方案中 被x取模后,值为k的方案数.(1<=k< ...
- cf 621E. Wet Shark and Blocks
神奇,矩阵乘法23333333333333333 递推式是很简单的(连我这种不会DP的人都写出来了.) 需要求出的是转移矩阵(还是叫系数矩阵的),也是最这个东西用快速幂. 这个东西的i,j大概就表示从 ...
- 【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 ...
- 【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 ...
- Wet Shark and Flowers(思维)
C. Wet Shark and Flowers time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
随机推荐
- c#中序列化
序列化(Serialization)是.NET平台的特性之一.1.为什么要序列化:首先你应该明白系列化的目的就不难理解他了.系列化的目的就是能在网络上传输对象,否则就无法实现面向对象的分布式计算.比如 ...
- 在Mac mini上安装 ESXi 5.5
Mac mini 是 mid 2011 版本的, 安装原版ESXi 5.5 update 1 非常顺利, 没遇到任何问题. 提示: 1. 安装会初始化整个硬盘, 有数据要先备份 2. ESXi只使用有 ...
- DPABI advanced edition 文件夹组织形式
❤ Regress out nuisance: ... csf\wm ('SPM apriori') {working directory}\Masks\WarpedMasks\SubIndex_Wh ...
- linux addr2line 定位so库崩溃位置
在Linux下写C/C++程序的程序员,时常与Core Dump相见.在内存越界访问,收到不能处理的信号,除零等错误出现时,我们精心或不精心写就的程序就直接一命呜呼了,Core Dump是Linux仁 ...
- Python快速教程目录(转)
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 怎么能快速地掌握Python?这是和朋友闲聊时谈起的问题. Python包含的内容 ...
- 小记sql server临时表与表变量的区别
临时表与表变量都可以起到“临时”的作用,那么两者主要的区别是什么呢? 这里不讨论创建方式,以及全局临时表.会话临时表这些,主要记录一下个人对两者的主要区别以及适用情况的看法,有什么不对或补充的地方,欢 ...
- Theano3.3-练习之逻辑回归
是官网上theano的逻辑回归的练习(http://deeplearning.net/tutorial/logreg.html#logreg)的讲解. Classifying MNIST digits ...
- MD5算法的C语言实现
1 #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <string.h ...
- 系统升级日记(3)- 升级SharePoint解决方案和Infopath
最近一段时间在公司忙于将各类系统进行升级,其最主要的目标有两个,一个是将TFS2010升级到TFS2013,另外一个是将SharePoint 2010升级到SharePoint 2013.本记录旨在记 ...
- Spring学习进阶(二)Spring IoC
在使用Spring所提供的各种丰富而神奇的功能之前,必须在Spring IoC容器中装配好Bean,并建立Bean与Bean之间的关联关系.控制反转(Inverser of Control ioc)是 ...