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 ...
随机推荐
- oc学习之对象在内存的位置
对象在内存中的存储 1. 内存中的五大区域. 栈: 存储局部变量. 堆: 允许程序员手动在堆区申请指定的连续的字节数的空间来使用. BSS段: 存储未初始化的全局变量.静态变量. 数据段(常量区): ...
- ShopNC_WAP
记录 ShopNC_WAP 端点点滴滴 插件记录 1. http://www.jiawin.com/swipe-mobile-touch-slider swiper 插件 2. https:// ...
- linux 学习-用户&群组&权限
Linux用户&群组&权限 ⦁ Linux安全性模型 1)Linux使用User和Group控制使用者对文件的存取权限 2)用户使用账号和口令登录Linux 3) ...
- C# Volatile 类
关于C#中Volatile类的具体信息,请访问MSDN: https://msdn.microsoft.com/en-us/library/system.threading.volatile(v=vs ...
- winServer2008下安装SqlServer2008数据库
1 安装文件包 文件名 cn_sql_server_2008_r2_enterprise_x86_x64_ia64_dvd_522233.iso SHA1 0EEFF017B21635DF33F33C ...
- [Android]Android SDk Manager中创建模拟器无法选择CPU问题解析
方法一.正常下载所需sdk包 启动 Android SDK Manager ,打开主界面,依次选择「Tools」.「Options...」,弹出『Android SDK Manager - Setti ...
- Android平台 视频编辑的高级版本
基本覆盖了秒拍,美拍,快手等视频编辑的大部分功能. 增加了44种滤镜,基本覆盖市面上大部分APP中的滤镜效果. 可以实现视频和视频, 视频和图片,视频和您的UI界面叠加. 在叠加的过程中:支持任意时间 ...
- HDU 5880 Family View
$AC$自动机. 用$AC$自动机匹配一次,开一个$flag$记录一下以$i$位置为结尾的最长要打$*$多少个字符,然后倒着扫描一次就可以输出了. #pragma comment(linker, &q ...
- jmeter java性能测试
本篇文章主要讲解jmeter如何测试java请求,以项目中某个接口为例,请求数据为post,返回也为post 1:新建maven工程,pom文件为 <project xmlns="ht ...
- F9 开发之左树右表中的左树
1 首先在前端应用树树控件 <div class="fui-left"> <div role="head" title="地区选择& ...