矩阵问题&&http://acm.hdu.edu.cn/showproblem.php?pid=1575
2011-11-25 15:35
441 查看
一道矩阵水题,,,,主要是二分法,,,终于1A了,,,
#include<iostream> #include<cstdio> #include<string.h> #define N 11 #define MOD 9973 using namespace std; typedef struct { int num ; }Node; Node a,b; int n,k; Node mul(Node x,Node y) { Node c; memset(c.num,0,sizeof(c.num)); for(int i=0;i<n;++i) for(int j=0;j<n;++j) { for(int t=0;t<n;++t) c.num[i][j]=(c.num[i][j]+x.num[i][t]*y.num[t][j])%MOD; } return c; } Node ceil() { Node p=a,q=b; while(k) { if(1&k) p=mul(p,q); q=mul(q,q); k=k>>1; } return p; } int main() { int Case; scanf("%d",&Case); while(Case--) { scanf("%d%d",&n,&k); for(int i=0;i<n;++i) for(int j=0;j<n;++j) scanf("%d",&b.num[i][j]),a.num[i][j]=(i==j); Node c=ceil(); int sum=0; for(int i=0;i<n;++i) sum+=c.num[i][i],sum%=MOD; printf("%d\n",sum); }return 0; }
相关文章推荐
- http://acm.hdu.edu.cn/showproblem.php?pid=3790&&最短路径问题
- http://acm.hdu.edu.cn/showproblem.php?pid=3591&&背包问题
- http://acm.hdu.edu.cn/showproblem.php?pid=2844&&背包问题
- 最大连续子序列&&http://acm.hdu.edu.cn/showproblem.php?pid=1231
- http://acm.hdu.edu.cn/showproblem.php?pid=2222&&AC自动机
- 欧拉回路的应用&&http://acm.hdu.edu.cn/showproblem.php?pid=3018
- http://acm.hdu.edu.cn/showproblem.php?pid=1055&&Color a Tree
- Buy the Ticket&&http://acm.hdu.edu.cn/showproblem.php?pid=1133
- http://acm.hdu.edu.cn/showproblem.php?pid=1075&&字典树
- http://acm.hdu.edu.cn/showproblem.php?pid=2256&&构造矩阵求值
- The 36th ACM/ICPC Asia Regional Beijing Site&&http://acm.hdu.edu.cn/showproblem.php?pid=4046
- find the safest road&&http://acm.hdu.edu.cn/showproblem.php?pid=1596
- http://acm.hdu.edu.cn/showproblem.php?pid=1114&&完全背包
- Saving Princess claire_&&http://acm.hdu.edu.cn/showproblem.php?pid=4308
- Substrings &&http://acm.hdu.edu.cn/showproblem.php?pid=1238
- http://acm.hdu.edu.cn/showproblem.php?pid=1116&&Play on Words
- http://acm.hdu.edu.cn/showproblem.php?pid=2191&&多重背包+二进制优化
- http://acm.hdu.edu.cn/showproblem.php?pid=1166&&线段树区间求和
- http://acm.hdu.edu.cn/showproblem.php?pid=2642&&二维树状数组
- http://acm.hdu.edu.cn/showproblem.php?pid=2838&&逆序数的应用