LA 3704 Cellular Automaton(循环矩阵)
来源:互联网 发布:信长之野望 知乎 编辑:程序博客网 时间:2024/05/08 00:50
题目链接
分析:这题矩阵规模略大,直接算下来要500^3*log(10^7),不过有个非常好的性质可以利用,循环矩阵*循环矩阵 = 循环矩阵 ,这样就可以将复杂度降低500;
参考代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 550;typedef long long LL;typedef LL Mat[maxn];int N,M,D,K,tot;Mat m[100];int E[maxn];LL ans[maxn];int Mul(int a,int b){ int r = ++tot; for(int i=0;i<N;i++){ LL sum = 0; for(int j=0;j<N;j++){ sum += m[a][j]*m[b][(i-j+N)%N]; } m[r][i] = sum % M; } return r;}int Pow(int n){ int e = 0,a=1; while(n){ if(n&1) e = Mul(e,a); a = Mul(a,a); n>>=1; } return e;}int main(){ //freopen("input.txt","r",stdin); while(scanf("%d%d%d%d",&N,&M,&D,&K)!=EOF){ tot = 1; for(int i=0;i<N;i++) scanf("%d",&E[i]); for(int i=0;i<N;i++){ m[0][i] = i==0 ? 1 : 0; m[1][i] = (i<=D || N-i<=D) ? 1 : 0; } int r = Pow(K); for(int i=0;i<N;i++){ ans[i] = 0; for(int j=0;j<N;j++){ ans[i] = (ans[i] + m[r][(j-i+N)%N] * E[j]) % M; } } printf("%lld",ans[0]); for(int i=1;i<N;i++) printf(" %lld",ans[i]); printf("\n"); } return 0;}
- LA 3704 Cellular Automaton(循环矩阵)
- LA 3704 Cellular Automaton【循环矩阵,快速幂】
- LA 3704 Cellular Automaton / 矩阵快速幂
- LA 3704 Cellular Automaton (矩阵快速幂)
- la 3704 - Cellular Automaton(矩阵优化递推)
- uva1386 - Cellular Automaton 循环矩阵
- Poj 3150/UVA 1386/UVALive 3704 Cellular Automaton 循环矩阵
- UVA Live 3704 Cellular Automaton (循环矩阵+快速幂)
- UVA 1386 - Cellular Automaton(循环矩阵)
- UVA 1386 Cellular Automaton(循环矩阵)
- UVA1386-Cellular Automaton(循环矩阵)
- POJ3150---Cellular Automaton(矩阵)
- poj3150 && LA3704 Cellular Automaton 矩阵乘法 + 循环矩阵性质
- uva 1386 - Cellular Automaton(循环矩阵+矩阵快速幂)
- UVA 1386 cellular automaton [循环矩阵+矩阵快速幂]【数学】
- poj_3150 Cellular Automaton(循环矩阵+矩阵乘法)
- 【循环矩阵+矩阵快速幂】Cellular Automaton UVA
- uva 1386 - Cellular Automaton(循环矩阵乘)
- 壳分析
- Html5新标签dialog的完美用处
- python 从共享文件中自动拷贝指定文件到本地
- 《黑马程序员》java网络编程知识梳理
- 微博项目---IOS项目开发流程
- LA 3704 Cellular Automaton(循环矩阵)
- 解决HDU爆栈的问题
- UIP UDP的补丁
- 第13周项目1:递归求奇数连乘的积
- 关于产品的一些思考——搜狐之搜狗输入法(手机版)
- hello,world
- jstl隔行显示不同的背景色与ajax隔行显示不同的颜色
- Cocos2d-x学习之windows 7 android环境搭建
- My97DatePicker使用和下载