2017 Wuhan University Programming Contest (Online Round) E. Lost in WHU(矩阵快速幂)
来源:互联网 发布:安捷伦66319d编程手册 编辑:程序博客网 时间:2024/05/22 08:04
Input file: standard inputOutput file: standard output Time limit: 1 secondMemory limit: 512 mebibytes
As one of the most beautiful campus in China, Wuhan University is around several hills, so the road is complex and visitors always lose themselves. Give a undirected graph of WHU of N points and a deadline, then you should count the number of plan to reach the destination by deadline (the starting point is 1 and the ending point is N).
Input
First line contains the number of points N (N≤100) and the number of edges M (M≤N(N−1)/2).
The i-th line of next M lines contains two numbers ui and vi, which respents an edge (ui,vi).
The last line contains the deadline T(T≤109).
Output
The number of plan to reach the destination by deadline module 109+7.
Examples
Input 1
4 51 32 33 41 21 48
Output 1
170
题目链接https://oj.ejq.me/problem/26
给出可以走的边,以及走的步数,问在这个步数内有多少种方案从1到达n,设置一下到达n后不能继续走,然后直接用矩阵快速幂即可
#include <iostream>#include <iomanip>#include<stdio.h>#include<string.h>#include<stack>#include<stdlib.h>#include<queue>#include<map>#include<math.h>#include<algorithm>#include<vector>#define mem(a,b) memset(a,b,sizeof(a))#define N 105#define inf 1000000007#define ll long longusing namespace std;struct Matrix{ ll m[N][N];};int n;Matrix res;//单位矩阵Matrix mul(Matrix a,Matrix b)//矩阵相乘{ Matrix c;mem(c.m,0); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) for(int k=1;k<=n;k++) c.m[i][j]=(c.m[i][j]+a.m[i][k]*b.m[k][j])%inf; return c;}Matrix fastm(Matrix a,int x)//矩阵快速幂{ while(x) { if(x&1) res=mul(res,a); x>>=1; a=mul(a,a); } return res;}int main(){ int m,x,y,t; while(cin>>n>>m) { Matrix a,b; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) res.m[i][j]=(i==j); } for(int i=1;i<=m;i++) { cin>>x>>y; a.m[x][y]=a.m[y][x]=1; if(y==n)a.m[y][x]=0;//到达n后不能再走 if(x==n)a.m[x][y]=0;//到达n后不能再走 } a.m[n][n]=1;//计算<=k步的路径总数,如果为0,则计算=k时的路径数 cin>>t; b=fastm(a,t); cout<<b.m[1][n]<<endl; }}
- 2017 Wuhan University Programming Contest (Online Round) E. Lost in WHU(矩阵快速幂)
- 2017 Wuhan University Programming Contest (Online Round) E. Lost in WHU(矩阵快速幂)
- 2017 Wuhan University Programming Contest (Online Round) ELost in WHU(矩阵快速幂
- 2017 Wuhan University Programming Contest --Lost in WHU
- 2017 Wuhan University Programming Contest (Online Round)(补题补题)
- E. Lost in WHU。矩阵快速幂!
- 2017 Wuhan University Programming Contest 现场赛I: A simple math problem(矩阵快速幂)
- 2017 Wuhan University Programming Contest 现场赛 I.A simple math problem(矩阵快速幂)
- 2017 Wuhan University Programming Contest (Online Round) D. Events,线段树区间更新+最值查询!
- Color(树形dp)——2017 Wuhan University Programming Contest (Online Round)
- 2017 Wuhan University Programming Contest (Online Round) A One car comes and one car goes
- [WOJ26 Lost in WHU]矩阵快速幂
- WHU B Color 2017 Wuhan University Programming Contest 一道简单树形dp
- 2017 Wuhan University Programming Contest 题解
- WOJ 26. Lost in WHU(矩阵快速幂变形)
- WOJ 26 Lost in WHU(矩阵快速幂+邻接矩阵乘法)
- 武大校赛 26. Lost in WHU(矩阵快速幂)
- 2017 Wuhan University Programming Contest 现场赛G. Room
- 自定义注解 @interface
- JS获取浏览器窗口大小 获取屏幕,浏览器,网页高度宽度
- Lightoj1261——1261
- 数据库自动化运维平台--元数据平台
- 数学3
- 2017 Wuhan University Programming Contest (Online Round) E. Lost in WHU(矩阵快速幂)
- OpenGL Shader简单例子
- linq中如何随机获取数据
- poj-1837-Balance
- [模拟]CODEVS-1160 蛇形矩阵
- 深度剖析之 PagerSlidingTabStrip
- 感悟
- Android 冷知识
- 梯度下降(Gradient Descent)