矩阵快速幂。

#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. 编写高性能SQL的注意事项

    在数据库部分,对数据库应用性能改进来说,需要重点关注应用程序,在查询设计和索引策略等方面进行优化,甚至可以把数据库查询效率提高数百倍,在其他方面的优化努力,其效果就没有这么明显(见下图).本文重点描述 ...

  2. 如何对Javascript代码进行二次压缩(混淆)

    如何对Javascript代码进行二次压缩(混淆) 对Javascript代码进行压缩(混淆),可以有效减少传输和加载时间.但是,不是所有的变量(方法)都能被混淆的,一般来说,只有非属性的变量(方法) ...

  3. Sara Chipps

    "To be a developer you really need to love to learn because you're going to be learning your en ...

  4. 负载均衡,最理想使用 redis实现session共享

    负载均衡在多台php服务器负载均衡的情况下,第一秒请求是a服务器,第二秒请求是b服务器, session必须放在一个公共的服务器,最理想是使用 redis实现session共享.内存的速度比磁盘访问快 ...

  5. ArrayList构造函数

    //1.摘要: //初始化 System.Collections.ArrayList 类的新实例,该实例为空并且具有默认初始容量. // public ArrayList(); ArrayList a ...

  6. USACO 3.1 Humble Numbers

    Humble Numbers For a given set of K prime numbers S = {p1, p2, ..., pK}, consider the set of all num ...

  7. C#隐藏tabcontrol

    //tabControl1.SizeMode = TabSizeMode.Fixed; //tabControl1.ItemSize = new Size(0, 1);

  8. 注意Thread.interrupt()方法的真正作用并不是用来中断线程

      程序是很简易的.然而,在编程人员面前,多线程呈现出了一组新的难题,如果没有被恰当的解决,将导致意外的行为以及细微的.难以发现的错误.      在本篇文章中,我们针对这些难题之一:如何中断一个正在 ...

  9. 【Python】迭代器

    对迭代器和生成器的概念一直很混乱,总结一下: 迭代器: 1.所谓的迭代器,就是具有__next__()方法的对象: 2.__iter__()方法返回一个迭代器对象,这个对象必须具有__next__() ...

  10. redis写shell与ssh免密码登陆

     redis-cli参数:-h :指定要连接的主机IP或域名-p :指定连接的端口-a :指定密码-r :执行指定的命令-n :数据库名-x :将最后一个参数输出为value redis写shell- ...