Codeforces621E 矩阵构造快速幂
来源:互联网 发布:淘宝店注册 编辑:程序博客网 时间:2024/06/06 12:35
比赛的时候 构造矩阵想岔了,矩阵构造熟练度明显不够。。。
ACCode:
#pragma comment(linker, "/STACK:1024000000,1024000000")#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<vector>#include<set>#include<map>#include<queue>#include<sstream>#include<string>#include<bitset>using namespace std;typedef long long LL;const LL LINF = (1LL <<63);const int INF = 1 << 31;const int NS = 100010;const int MS = 10;const int KS = 105;const LL MOD = 1000000007;struct matrix{ #define M_SIZE (KS) int len; int a[M_SIZE][M_SIZE]; void initClear(int _len) { len = _len; memset(a, 0, sizeof(a)); } void initOne(int _len) { initClear(_len); for(int i = 0; i < len; i++) { a[i][i] = 1; } } void initStruct(int _len, int* dig) { initClear(_len); int lim = min(MS, len); for(int i = 0; i < len; i++) { for(int j = 0; j < lim; j++) { int vi = (i * 10 + j) % len; a[i][vi] += dig[j]; } } } matrix operator * (const matrix &right)const { matrix res; res.initClear(len); for(int row = 0; row < len; row++) { for(int col = 0; col < len; col++) { for(int pos = 0; pos < len; pos++) { if(a[row][pos] > 0 && right.a[pos][col]) { res.a[row][col] += ((LL)a[row][pos] * right.a[pos][col]) % MOD; if(res.a[row][col] >= MOD) { res.a[row][col] -= MOD; } } } } } return res; } matrix operator + (const matrix &right)const { matrix res; res.initClear(len); for(int row = 0; row < len; row++) { for(int col = 0; col < len; col++) { res.a[row][col] = (this->a[row][col] + right.a[row][col]); if(res.a[row][col] >= MOD) { res.a[row][col] -= MOD; } else if(res.a[row][col] < 0) { res.a[row][col] += MOD; } } } return res; } matrix qpow(LL y) { matrix ans; ans.initOne(this->len); matrix x; x = *this; for(;y > 0; y >>= 1) { if(y & 1) { ans = ans * x; } x = x * x; } return ans; } void print() { for(int row = 0; row < len; row++) { for(int col = 0; col < len; col++) { cout<<this->a[row][col]<<" "; } puts(""); } puts(""); }};int n, b, k, x;int dig[MS];matrix mat;int main(){#ifndef ONLINE_JUDGE freopen("621E.in", "r", stdin);// freopen("out.txt", "w", stdout);#endif while(~scanf("%d %d %d %d", &n, &b, &k, &x)) { int d; memset(dig, 0, sizeof(dig)); for(int i = 0; i < n; i++) { scanf("%d", &d); dig[d]++; } if(x < MS) { for(int i = x; i < MS; i++) { dig[i % x] += dig[i]; dig[i] = 0; } } mat.initStruct(x, dig);// mat.print();// printf("-------------\n"); mat = mat.qpow(b);// mat.print();// printf("-------------\n"); printf("%d\n", mat.a[0][k]); } return 0;}
0 0
- Codeforces621E 矩阵构造快速幂
- 快速矩阵幂 Codeforces621E Wet Shark and Blocks
- codeforces621E————Wet Shark and Blocks(动态规划,矩阵快速幂)
- 构造矩阵+矩阵快速幂
- hdoj 5015 构造矩阵+矩阵快速幂
- hdu4565 矩阵构造+矩阵快速幂
- 纪念SlingShot 矩阵快速幂 构造矩阵
- BZOJ 3240 构造矩阵+矩阵快速幂
- BZOJ 1898 构造矩阵+矩阵快速幂
- 矩阵构造+矩阵快速幂-HDU5950
- 构造矩阵+矩阵快速幂 POJ3735
- UVA10655矩阵快速幂(构造矩阵)
- hdu_2276_构造矩阵_快速幂乘
- ZOJ 3857 Hypersphere 构造 + 矩阵快速幂
- hdu 2256【矩阵快速幂 构造】
- POJ3233Matrix Power Series 矩阵快速幂(分块矩阵构造)
- UVa 10870 - Recurrences (矩阵构造 矩阵快速幂)
- HDU 5015 - 233 Matrix (矩阵构造 矩阵快速幂)
- java中queue的使用
- poj1111 这道题目很巧妙的运用了反向思维来搜索
- nao机器人国际比赛程序 python编写
- CMD实现本地文件(夹)拷贝到服务器
- java 参数 -Xms -Xmx -Xss
- Codeforces621E 矩阵构造快速幂
- Android开发之BUG专讲:入门篇(一)
- 7天学习opengl入门
- Andrlid ListView原理理解与应用
- 单链表操作 头插入 尾插入 链表反转
- Build glibc-2.6
- Android图片处理之高斯模糊示例——仿微信朋友圈照片模糊效果
- ruby元编程4------类
- jquery $(document).ready() 与window.onload的区别