矩阵快速幂。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
} int MOD=;
int T,n,m,k; struct Matrix
{
int A[][];
int R, C;
}; Matrix X, Y, Z; Matrix cheng(Matrix a, Matrix b)
{
Matrix c; int i, j, k;
for (i = ; i <= a.R; i++)
for (j = ; j <= b.C; j++)
{
c.A[i][j]=;
for (k = ; k <= a.C; k++)
c.A[i][j] = (c.A[i][j] + (a.A[i][k] * b.A[k][j]) % MOD) % MOD;
} c.R = a.R; c.C = b.C; return c;
} void init()
{
memset(X.A, , sizeof X.A);
memset(Y.A, , sizeof Y.A); Y.R = n; Y.C = n;
for (int i = ; i <= n; i++) Y.A[i][i] = ; for(int i=;i<=m;i++)
{
int a,b; scanf("%d%d",&a,&b);
X.A[a][b]=;
} X.R = n; X.C = n;
} void work()
{
while (k)
{
if (k % == ) Y = cheng(Y,X);
k = k >> ;
X = cheng(X,X);
}
printf("%d\n",Y.A[][n]);
} int main()
{
while(~scanf("%d%d%d",&n,&m,&k))
{
init();
work();
}
return ;
}

FZU 1627 Revival's road的更多相关文章

  1. Problem 2238 Daxia & Wzc's problem 1627 瞬间移动

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1627 http://acm.fzu.edu.cn/problem.php ...

  2. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  3. POJ 3204 Ikki's Story I - Road Reconstruction

    Ikki's Story I - Road Reconstruction Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 7 ...

  4. FZU 2137 奇异字符串 后缀树组+RMQ

    题目连接:http://acm.fzu.edu.cn/problem.php?pid=2137 题解: 枚举x位置,向左右延伸计算答案 如何计算答案:对字符串建立SA,那么对于想双延伸的长度L,假如有 ...

  5. FZU 1914 单调队列

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=1914 题意: 给出一个数列,如果它的前i(1<=i<=n)项和都是正的,那么这个数列是正的,问这个 ...

  6. ACM: FZU 2105 Digits Count - 位运算的线段树【黑科技福利】

     FZU 2105  Digits Count Time Limit:10000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  7. FZU 2112 并查集、欧拉通路

    原题:http://acm.fzu.edu.cn/problem.php?pid=2112 首先是,票上没有提到的点是不需要去的. 然后我们先考虑这个图有几个连通分量,我们可以用一个并查集来维护,假设 ...

  8. ACM: FZU 2107 Hua Rong Dao - DFS - 暴力

    FZU 2107 Hua Rong Dao Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I6 ...

  9. ACM: FZU 2112 Tickets - 欧拉回路 - 并查集

     FZU 2112 Tickets Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u P ...

随机推荐

  1. String.split()分割字符串

    string.split(s[, sep[, maxsplit]]) Return a list of the words of the string s. If the optional secon ...

  2. jmeter(八)-JDBC请求(sqlserver)

    做JDBC请求,首先要了解这个JDBC对象是什么,然后寻找响应的数据库连接URL和数据库驱动. 数据库URL:jdbc:sqlserver://200.99.197.190:1433;database ...

  3. python爬虫---python3.5---eclipse

    解析中文会出现\xbe\c8\90\hd........ 这个和你的编码选择有关.如果是解析成html,则需 fout = open('output.html', 'w',encoding='utf- ...

  4. 记JavaScript的入门学习(二)

    2016年11月25号,利用上午时间学习了JavaScript的数据类型和变量,下午就该去图书馆泡书了. 看完变量的本章节,发现我可能不能一天结束,那我就利用上午和晚上九点回来的时间完成吧.把心态调整 ...

  5. 运用PhantomJS测试JavaScript

    我认为我不需要说服你,测试你的JavaScript代码是一个好主意.但是,测试需要DOM操作的JavaScript代码有时候确是繁琐的.这意味着你需要在浏览器中测试代码而不能使用终端,对吗?错了,事实 ...

  6. WEB典型应用

  7. C# IDisposable的理解

    C#里可以嵌入非托管代码,这就涉及到了这些代码资源的释放.以前总是看到别人的代码里那么写,也没有好好想想为什么,今天看了书,总结一下. 资源释放分为两种: 托管的 非托管的 两者的释放方式不一致: 没 ...

  8. ios UIImageView处理图片大小问题

    UIImageView视图可以显示图片 实例化UIImageView有两种方法 第一种方法: UIImageView *myImageView = [[ UIImageView alloc] init ...

  9. ASP.NET里面,如果设置了form的 onsubmit="return false;"之后,就不能提交按钮了?

    我的按钮是写成的服务器控件的形式<asp:Button ID="btnSubmitBR" runat="server" Text="提交&quo ...

  10. Laravel生成编译文件权限问题

    sudo -unobody ./artisan optimize # 避免`fpm`账户无权限修改缓存文件的问题.这里的`nobody`改成实际的`fpm`用户名.