题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=15129

【思路】

矩阵乘法-循环矩阵

题目中的转移矩阵是一个循环矩阵,循环矩阵的乘积依旧是循环矩阵,这样保留矩阵第一行进行快速幂乘法即可。

【代码】

 #include<cstdio>
#include<cstring>
#include<iostream>
using namespace std; typedef long long LL;
const int N = +; int m,n,d,k; void mul(LL a[],LL b[]) {
LL c[N];
for(int i=;i<n;i++) {
c[i]=;
for(int j=;j<n;j++)
c[i]=(c[i]+a[j]*b[(i-j+n)%n])%m;
}
memcpy(a,c,sizeof(c));
}
LL ans[N],tmp[N],A[N]; void pow(int p) {
memset(ans,,sizeof(ans));
memset(tmp,,sizeof(tmp));
for(int i=-d;i<d+;i++) {
tmp[(i+n)%n]=;
}
ans[]=;
while(p) {
if(p&) mul(ans,tmp);
mul(tmp,tmp);
p>>=;
}
} int main() {
while(scanf("%d%d%d%d",&n,&m,&d,&k)==) {
pow(k);
for(int i=;i<n;i++) scanf("%d",&A[i]);
mul(ans,A);
printf("%lld",ans[]);
for(int i=;i<n;i++) printf(" %lld",ans[i]);
putchar('\n');
}
return ;
}

UVa 3704 Cellular Automaton(矩乘)的更多相关文章

  1. UVA 1386 - Cellular Automaton(循环矩阵)

    UVA 1386 - Cellular Automaton option=com_onlinejudge&Itemid=8&page=show_problem&category ...

  2. LA 3704 Cellular Automaton

    题意概述: 等价地,本题可以转化为下面的问题: 考虑$n \times n$的$0-1$矩阵$A$,在第$i$行上第$[-d+i, d+i]$(模$n$意义下)列对应的元素为$1$,其余为$0$.求$ ...

  3. UVA 1386 Cellular Automaton

    矩阵快速幂. 样例是这样构造矩阵的: 矩阵很好构造,但是500*500*500*logk的复杂度显然是无法通过这题的. 其实本题构造出来的矩阵是一个循环矩阵,只需直到第一行或者第一列,即可直到整个矩阵 ...

  4. UVaLive 3704 Cellular Automaton (循环矩阵 + 矩阵快速幂)

    题意:一个细胞自动机包含 n 个格子,每个格子取值是 0 ~ m-1,给定距离,则每次操作后每个格子的值将变成到它距离不超过 d 的所有格子在操作之前的值之和取模 m 后的值,其中 i 和 j 的距离 ...

  5. UVA1386 【Cellular Automaton】题解

    题面:UVA1386 Cellular Automaton 矩阵乘法+快速幂解法: 这是一个比较裸的有点复杂需要优化的矩乘快速幂,所以推荐大家先做一下下列洛谷题目练练手: (会了,差不多就是多倍经验题 ...

  6. 【POJ】3150 Cellular Automaton(矩阵乘法+特殊的技巧)

    http://poj.org/problem?id=3150 这题裸的矩阵很容易看出,假设d=1,n=5那么矩阵是这样的 1 1 0 0 1 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 ...

  7. [POJ 3150] Cellular Automaton (矩阵高速幂 + 矩阵乘法优化)

    Cellular Automaton Time Limit: 12000MS   Memory Limit: 65536K Total Submissions: 3048   Accepted: 12 ...

  8. POJ 3150 Cellular Automaton(矩阵快速幂)

    Cellular Automaton Time Limit: 12000MS Memory Limit: 65536K Total Submissions: 3504 Accepted: 1421 C ...

  9. POJ - 3150 :Cellular Automaton(特殊的矩阵,降维优化)

    A cellular automaton is a collection of cells on a grid of specified shape that evolves through a nu ...

随机推荐

  1. Angularjs总结(一)表单验证

    常用的表单验证1.必须字段html5特性 增加required <input type="text" required /> 2.最小长度和最大长度 <input ...

  2. 【工具篇】notepad++

    一直都是使用notepad++来写程序,感觉比UE好用多了,没有UE那么重.前段时间网上还做了一个调查,notepad++在国外使用排行还是非常高的,在国内也是很流行.以下记录一些比较实用的技巧. 一 ...

  3. 校省选赛第一场A题Cinema题解

    今天是学校省选的第一场比赛,0战绩收工,死死啃着A题来做,偏偏一直WA在TES1. 赛后,才发现,原来要freopen("input.txt","r",stdi ...

  4. 谈memcache和memcached的区别

    用了段时间的memcache和memcached总结下认识,看很多人在用cache的时候,刚刚都没有搞清楚memcache 和 memcached的区别,还有就是使用的时候基本都是 get/set   ...

  5. [Linux]命令行模式切换

    图形界面进入命令:Ctrl+Alt+T 进入终端命令:Ctrl+Alt+F1 or Ctrl+Alt+F2 切换至图形界面:按Alt+F7

  6. 运用预加载提升H5移动页面的用户体验

    原文地址:http://www.grycheng.com/?p=2188 在做h5移动页面,相信大家一定碰到过页面已经打开,但是里面的图片还未加载出来的情况,这种问题虽然不影响页面的功能,但是不利于用 ...

  7. hadoop namenode多次格式化后,导致datanode启动不了

    jps hadoop namenode -format dfs directory : /home/hadoop/dfs --data --current/VERSION #Wed Jul :: CS ...

  8. secureCRT使用小贴士

    (一)使用WIN键盘 在securecrt界面:工具→键映射编辑器,在弹出的键盘中点击“home”,会弹出一个窗口,在“发送字符串”中输入:\033[1~ 另存为securecrt安装根目录下的Key ...

  9. JsRender

    JsRender 不少前端人员应该都用过,它是一个比较强大的模板,不牵涉太多技术依赖,使用起来非常舒服.我本人在前端开发中使用React之前,都是用的它了(实际上我感觉React没有JsViewes好 ...

  10. 支付宝集成SDK 报错

    1.打开Demo中的错误 这是路径错误导致 解决办法:在Build Settings 中找到 Library Search Paths ,去掉其中的 /// 2.自己集成支付宝SDK时的错误 这个也是 ...