[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 ...
随机推荐
- 快速编写代码zencode
#是 id .是class $是数字 {}是标签中内容 *个数 ^上一级
- 我使用celery以及docker部署遇到的问题
首先我本机测试时没有问题的,但是在线上docker中,任务一直显示 "Sending due task".超时的任务是 django orm update 操作,本地不会出现这样的 ...
- weblogic下部署应用时slf4j与logbak冲突的解决办法
今天在weblogic上部署一个使用logback的应用时,报错如下: java.lang.IllegalArgumentException: Invalid 'logbackConfigLocati ...
- [MetaHook] Quake FMOD player demo
CFMOD.h #ifndef CFMOD_H #define CFMOD_H #include "qfmod.h" struct Sound_t { char *pszName; ...
- ROS(Robot Operating System)常用环境变量介绍
本文简单介绍ROS系统中常用的环境变量用途及设置方式.ROS系统环境中除了必须配置的环境变量以外,其他的也是十分有用,通过修改变量路径,可以设置ROS系统中log文件存放路径,单元测试结果存放路径等. ...
- <实训|第十二天>用LVM对linux分区进行动态扩容
[root@localhost~]#序言在linux中,我们安装软件的途径一般有那些,你们知道吗?在linux中,如果你的磁盘空间不够用了,你知道如何来扩展磁盘吗?动态扩容不仅在工作中还是在其他方面都 ...
- WPF制作的小型笔记本-仿有道云笔记
楼主所在的公司不允许下载外部资源, 不允许私自安装应用程序, 平时记录东西都是用记事本,时间久了很难找到以前记的东西. 平时在家都用有道笔记, 因此就模仿着做了一个, 先看下实际运行图片: 1. 初始 ...
- [已开源/文章教程]独立开发 一个社交 APP 的源码/架构分享 (已上架)
0x00 背景 真不是和被推荐了2天的博客园一位大神较真,从他那篇文章的索引式文章内容也学习到了很多东西,看评论区那么多对社交APP源码有兴趣的,正巧我上周把我的一个社交APP开源了,包括androi ...
- Bootstrap系列 -- 10. 网格布局
一. 实现原理 网格布局是通过容器的大小,平均分为12份(可以修改),再调整内外边距,和表格布局有点类似但是也存在区别. 实现步骤如下: (1) 数据行.row 必须包含在容器.container 中 ...
- 系统升级日记(1)- 升级到SQL Server 2012
最近一段时间在公司忙于将各类系统进行升级,其最主要的目标有两个,一个是将TFS2010升级到TFS2013,另外一个是将SharePoint 2010升级到SharePoint 2013.本记录旨在记 ...