FZU 1627 Revival's road
矩阵快速幂。
#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的更多相关文章
- Problem 2238 Daxia & Wzc's problem 1627 瞬间移动
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1627 http://acm.fzu.edu.cn/problem.php ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- POJ 3204 Ikki's Story I - Road Reconstruction
Ikki's Story I - Road Reconstruction Time Limit: 2000MS Memory Limit: 131072K Total Submissions: 7 ...
- FZU 2137 奇异字符串 后缀树组+RMQ
题目连接:http://acm.fzu.edu.cn/problem.php?pid=2137 题解: 枚举x位置,向左右延伸计算答案 如何计算答案:对字符串建立SA,那么对于想双延伸的长度L,假如有 ...
- FZU 1914 单调队列
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1914 题意: 给出一个数列,如果它的前i(1<=i<=n)项和都是正的,那么这个数列是正的,问这个 ...
- ACM: FZU 2105 Digits Count - 位运算的线段树【黑科技福利】
FZU 2105 Digits Count Time Limit:10000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- FZU 2112 并查集、欧拉通路
原题:http://acm.fzu.edu.cn/problem.php?pid=2112 首先是,票上没有提到的点是不需要去的. 然后我们先考虑这个图有几个连通分量,我们可以用一个并查集来维护,假设 ...
- ACM: FZU 2107 Hua Rong Dao - DFS - 暴力
FZU 2107 Hua Rong Dao Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I6 ...
- ACM: FZU 2112 Tickets - 欧拉回路 - 并查集
FZU 2112 Tickets Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u P ...
随机推荐
- C语言之位运算
位运算 1).定义. 指的是1个二进制数据的每一位来参与运算. 位运算的前提: 是这个数必须是1个二进制. 注意: a). 参与位运算的二进制数据必须是补码形式. b). 位运算的结果也是二进制的补码 ...
- Oracle 列操作(增加列,修改列,删除列)
1.增加一列: Alter table 表名 add 列名 varchar2(10); 2.修改一列: Alter table 表名 modify 列名 varchar2(20); 3.删除一列: A ...
- Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)的解决方法
在连接数据库时,报这个错误,是/var/lib/mysql/ 目录下没有mysql.sock文件,在服务器搜索myslq.sock文件,我的是在/tmp/mysql.sock 解决方法是加一个软链: ...
- angularJS 自定义元素和属性
创造自定义元素和属性的方法是:directive('string',function(){ return{}; }); ①函数接收两个参数:一个字符串(指令的名字),一个函数: ②回调函数必须返回一个 ...
- ShopNC_WAP
记录 ShopNC_WAP 端点点滴滴 插件记录 1. http://www.jiawin.com/swipe-mobile-touch-slider swiper 插件 2. https:// ...
- VFL语言使用
- Spring MVC中页面向后台传值的几种方式
在学习 Spring Mvc 过程中,有必要来先了解几个关键参数: @Controller: 在类上注解,则此类将编程一个控制器,在项目启动 Spring 将自动扫描此类,并进行对 ...
- jQuery中操作Ajax方法小结
有时候,越深入去了解一个点,越发觉得自己无知,而之前当自己晓得一两个片面的点还洋洋自得,殊不知,这是多么讽刺 jQery对Ajax操作进行了封装,常见的 ajax()属于最底层的方法,使用频率很高的 ...
- 真的了解JS么?
1.setTimeout setTimeout(function(){ }),1000) setTimeout(function(num){ alert(num) //弹123 },1000,1 ...
- iOS缓存
存储缓存: 第三方应用只能把信息保存在应用程序的沙盒中.因为缓存数据不是用户产生的,所以它应该被保存在NSCachesDirectory,而不是NSDocumentsDirectory.为缓存数据创建 ...