矩阵快速幂。

#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. Android自定义控件系列(一)—Button七十二变

    转载请注明出处:http://www.cnblogs.com/landptf/p/6290791.html 忙了一段时间,终于有时间整理整理之前所用到的一些知识,分享给大家,希望给同学们有些帮助,同时 ...

  2. Semaphore初探

    示例一: package com.smbea.demo.semaphore; import java.util.concurrent.ExecutorService; import java.util ...

  3. SAP CRM 为用户创建业务合作伙伴并分配到组织单位

    想要在SAP CRM的前台完成一些操作,需要登录的用户在系统中存在对应的业务合作伙伴才可以,某些情况下,还需要被分配到正确的公司.部门.职位.下面是相关的操作步骤. 本文假定读者已经拥有一个开发帐号. ...

  4. C++继承、多态、虚函数

    #答案:http://www.cnblogs.com/tinaluo/articles/6290994.html 1 编写程序:定义一个抽象基类sharpe,只有包含一个求面积的纯虚函数,派生出矩形类 ...

  5. 二、mongo数据库

    官网:https://www.mongodb.com/ 进入官网 右上角有个下载按钮Download 1.完成安装后:运行--cmd(命令面板) 2.常用命令: 打开数据库 mongod –dbpat ...

  6. POJ3177 Redundant Paths 双连通分量

    Redundant Paths Description In order to get from one of the F (1 <= F <= 5,000) grazing fields ...

  7. 毕向东_Java基础视频教程第19天_IO流(11~14)

    第19天-11-IO流(字节流File读写操作) import java.io.FileInputStream; import java.io.FileOutputStream; import jav ...

  8. 【.NET】Linq几样特点

    LinQ 是 .net framework 3.5的技术,对集合的查询和操作十分方便,结合LinQ Provider ,可以更方便操作XML和SQL(或Entity). LinQ有6样常用的特性: 自 ...

  9. [Bzoj]1012最大数maxnumber

    题目如上(线段树???),蒟蒻第二眼想法(其实这道题正解是单队的说,但蒟蒻刚学线段树,于是...就) 献上黑历史: RE是因为蒟蒻数组开太小:第一次开110000:第二次开200000:结果就………… ...

  10. DBCP连接池的使用

    1.新建工程 2.导入commons-dbcp commons-logging commons-pool这三个包 3.创建dbcpconfig.properties的文件 实例如下 #连接设置 dri ...