Sicily1211(矩阵相乘)
来源:互联网 发布:淘宝降价通知如何设置? 编辑:程序博客网 时间:2024/05/21 09:27
邻接矩阵相乘n次后得到矩阵A,A[i][j]表示从i出发恰好走过n条边到达j的情况数。
#include <cstdio>#include <iostream>using namespace std;int main(){ int n,m,L; scanf("%d%d%d",&n,&m,&L); int i,j; int A[101][101]={{0}}; int a,b; for (i=1;i<=m;i++) { scanf("%d%d",&a,&b); A[a][b]=1; } int ans[101][101]; for (i=1;i<=n;i++) for (j=1;j<=n;j++) ans[i][j]=A[i][j]; L--; int anstemp[101][101]; while (L--) { int x,y; int temp=0; for (x=1;x<=n;x++) for (y=1;y<=n;y++) { for (i=1;i<=n;i++) temp+=ans[x][i]*A[i][y]; anstemp[x][y]=temp; temp=0; } for (x=1;x<=n;x++) for (y=1;y<=n;y++) ans[x][y]=anstemp[x][y]; } int q; int s,e; scanf("%d",&q); for (i=1;i<=q;i++) { scanf("%d%d",&s,&e); printf("%d\n",ans[s][e]); } return 0;}
- Sicily1211(矩阵相乘)
- 矩阵相乘
- 矩阵相乘
- 矩阵相乘
- 矩阵相乘
- 矩阵相乘
- 矩阵相乘
- 矩阵相乘
- 矩阵相乘
- 矩阵相乘
- 矩阵相乘
- 矩阵相乘
- 矩阵相乘
- 矩阵相乘
- 矩阵相乘
- 矩阵相乘
- 矩阵相乘
- 矩阵相乘!
- Hadoop2.0 YARN cloudra4.4.0安装配置
- mmap
- shell脚本中字符串比较经常遇到的一个问题
- AJAX三级联动省市选择,使用jquery+html+XML
- 字符设备驱动小计
- Sicily1211(矩阵相乘)
- C++与JAVA语言区别
- 如何优化移动网站,快速响应如本地应用
- Hadoop2.0 YARN cloudra4.4.0 WordCount实例
- 11.14C程序设计语言--指针类型
- Ubuntu 12.04安装Go语言运行环境,第一个程序Hello world
- 水
- HPUX LINUX AIX下的VG相关操作
- opencv学习-读写xml