FZU 1627 Revival's road

来源:互联网 发布:ei compendex数据库 编辑:程序博客网 时间:2024/06/14 08:53
Problem 1627 Revival's road

Accept: 209    Submit: 427
Time Limit: 5000 mSec    Memory Limit : 32768 KB

Problem Description

Oaiei is idle, and recently he wants to travel around the country. In his country there are N cities, they are numbered from 1 to N. There are roads between some cities, but some are not directly connected with each other. Oaiei lives in the city 1, and he wants to go to city N. Now, he has a question. In k steps, he would like to know there are how many ways from city 1 to city N. You should note that althought there is a road between city A and city B, there is not necessarily a road between city B and city A.

Input

There are multiple tests. For each test, the first line contains three integers N、M and k(2<=N<=100,1<=M<=N*N,1<=k<=10^9), N denotes the number of cities, M denotes the number of roads between the N cities. Following M lines, each line contains two integers A and B, denoting there is a road between city A and city B.

Output

There are how many ways from city 1 to city N. Becase the answer can be very large, you should output the answer MOD 10000.

Sample Input

4 5 91 22 33 44 11 34 5 11 22 33 44 11 3

Sample Output

3 0

Source

Summer Training Qualification II 




直接矩阵快速幂,没什么说的。



#include<iostream>#include<algorithm>#include<cstring>using namespace std;int n, m, k;struct matrix{int num[111][111];}mp,res;const int mod = 10000;matrix mul_matrix(matrix a,matrix b){matrix cmp;for (int i = 1; i <= n; i++){for (int j = 1; j <= n; j++){cmp.num[i][j] = 0;for (int k = 1; k <= n; k++){(cmp.num[i][j] += a.num[i][k] * b.num[k][j])%=mod;}}}return cmp;}void quick(){while (k){if (k & 1){res = mul_matrix(res, mp);}k >>= 1;mp = mul_matrix(mp, mp);for (int i = 1; i <= n; i++){for (int j = 1; j <= n; j++){cout << mp.num[i][j] << " ";}cout << endl;}}}int main(){int x, y;while (~scanf("%d%d%d",&n, &m, &k)){memset(mp.num, 0, sizeof(mp.num));memset(res.num, 0, sizeof(res.num));for (int i = 0; i <= n; i++){mp.num[i][i] = 1;res.num[i][i] = 1;}for (int i = 0; i < m; i++){scanf("%d%d", &x, &y);mp.num[x][y] = 1;}quick();cout << res.num[1][n] << endl;}return 0;}


原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 两岁宝宝吐口水怎么办 3岁宝宝不愿自己吃饭怎么办 婆家的人很烦人怎么办 三十了还没结婚怎么办 两岁宝贝断奶粉怎么办 宝宝断了母乳不吃奶粉怎么办 一岁宝宝不爱吃辅食怎么办 断奶后宝宝抗拒奶瓶怎么办 两岁宝宝断奶后不喝奶粉怎么办 两岁宝宝断奶不吃奶粉怎么办 宝宝断奶妈妈涨奶怎么办 三岁宝宝智商低怎么办 宝宝断奶晚上哭的厉害怎么办 2岁宝宝半夜喝奶粉怎么办 两岁宝宝不爱吃饭怎么办 快两岁的宝宝不爱吃饭怎么办 宝宝断奶后不愿意喝奶粉怎么办 宝宝断奶了不愿意喝奶怎么办? 宝宝断奶不愿意喝奶粉怎么办 宝宝断奶不愿意喝牛奶怎么办? 四个月宝宝断奶不吃奶粉怎么办 2岁不开口说话怎么办 八个月宝宝断奶不吃奶粉怎么办 宝宝断奶不喝奶粉怎么办 周岁 给娘家东西婆家看见怎么办 自己娘家妈总说婆家人坏话怎么办 娘家婆家老公都没有依靠怎么办? 2岁宝宝断奶粉怎么办 2岁宝宝夜奶频繁怎么办 宝宝15个月还在吃夜奶怎么办 宝宝两岁四个月还吃母乳怎么办 宝宝睡前老是找奶吃怎么办 宝宝戒奶晚上哭怎么办 宝宝戒奶半夜哭怎么办 吸习惯母乳不吸奶嘴怎么办 八个月宝宝奶睡怎么办 宝宝要吸着奶睡怎么办 戒母乳胸胀的疼怎么办 断奶孩子晚上哭的厉害怎么办 喜欢咬指甲的人怎么办? 成年了还咬指甲怎么办