题面

题解

如果给我们的是一个邻接矩阵,那么直接给邻接矩阵\(T\)次幂即可。

这里的图有边权,那么我们就将它拆成\(9\)个点即可。

代码

#include<cstdio>
#include<cstring>
#include<algorithm>
#define RG register
#define file(x) freopen(#x".in", "r", stdin);freopen(#x".out", "w", stdout); inline int read()
{
int data = 0, w = 1;
char ch = getchar();
while(ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if(ch == '-') w = -1, ch = getchar();
while(ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
return data * w;
} inline int read_char()
{
char ch = getchar();
while(ch < '0' || ch > '9') ch = getchar();
return (ch ^ 48);
} const int maxn(110), Mod(2009); int n, T;
inline int Num(const int &x, const int &y) { return x + y * n; } struct Matrix
{
int a[maxn][maxn], n;
Matrix(int n = 0) : n(n) { memset(a, 0, sizeof(a)); } inline int *operator [] (const int &id) { return a[id]; }
inline Matrix operator * (const Matrix &b)
{
Matrix c(n);
for(RG int i = 1; i <= n; i++)
for(RG int j = 1; j <= n; j++)
for(RG int k = 1; k <= n; k++)
c[i][k] = (c[i][k] + a[i][j] * b.a[j][k]) % Mod;
return c;
}
}; int main()
{
n = read(); T = read();
Matrix S(n * 9), A(n * 9);
for(RG int i = 1; i <= n; i++)
{
for(RG int j = 1; j < 9; j++)
S[Num(i, j)][Num(i, j - 1)] = 1;
for(RG int j = 1, x; j <= n; j++)
if((x = read_char())) S[i][Num(j, x - 1)] = 1;
} for(RG int i = 1; i <= A.n; i++) A[i][i] = 1;
while(T) { if(T & 1) A = A * S; S = S * S, T >>= 1; }
printf("%d\n", A[1][n]);
return 0;
}

【SCOI2009】迷路的更多相关文章

  1. BZOJ 1297: [SCOI2009]迷路( dp + 矩阵快速幂 )

    递推式很明显...但是要做矩阵乘法就得拆点..我一开始很脑残地对于每一条权值v>1的边都新建v-1个节点去转移...然后就TLE了...把每个点拆成9个就可以了...时间复杂度O((9N)^3* ...

  2. 1297: [SCOI2009]迷路

    1297: [SCOI2009]迷路 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 652  Solved: 442[Submit][Status] ...

  3. 【矩阵快速幂】bzoj1297 [SCOI2009]迷路

    1297: [SCOI2009]迷路 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1407  Solved: 1007[Submit][Status ...

  4. [BZOJ 1297][SCOI2009]迷路

    1297: [SCOI2009]迷路 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1418  Solved: 1017[Submit][Status ...

  5. B20J_1297_[SCOI2009]迷路_矩阵乘法

    B20J_1297_[SCOI2009]迷路_矩阵乘法 题意:有向图 N 个节点,从节点 0 出发,必须恰好在 T 时刻到达节点 N-1.总共有多少种不同的路径? 2 <= N <= 10 ...

  6. 【BZOJ1297】[SCOI2009]迷路(矩阵快速幂)

    [BZOJ1297][SCOI2009]迷路(矩阵快速幂) 题面 BZOJ 洛谷 题解 因为边权最大为\(9\),所以记录往前记录\(9\)个单位时间前的.到达每个点的方案数就好了,那么矩阵大小就是\ ...

  7. bzoj1297 / P4159 [SCOI2009]迷路

    P4159 [SCOI2009]迷路 如果边权只有 0/1 那么不就是一个灰常简单的矩阵快速幂吗! 然鹅边权 $<=9$ 所以我们把每个点拆成9个点! 解决~ #include<iostr ...

  8. [Bzoj1297][Scoi2009 ]迷路 (矩阵乘法 + 拆点)

    1297: [SCOI2009]迷路 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1385  Solved: 993[Submit][Status] ...

  9. BZOJ1297: [SCOI2009]迷路 矩阵快速幂

    Description windy在有向图中迷路了. 该有向图有 N 个节点,windy从节点 0 出发,他必须恰好在 T 时刻到达节点 N-1. 现在给出该有向图,你能告诉windy总共有多少种不同 ...

  10. 1297. [SCOI2009]迷路【矩阵乘法】

    Description windy在有向图中迷路了. 该有向图有 N 个节点,windy从节点 0 出发,他必须恰好在 T 时刻到达节点 N-1. 现在给出该有向图,你能告诉windy总共有多少种不同 ...

随机推荐

  1. oracle exp 无法导出空表

    oracle exp 无法导出空表   select 'alter table '|| a.table_name ||' allocate extent;' from user_tables a wh ...

  2. Exp6 信息收集与漏洞扫描 20164314

    一.实践目标 掌握信息搜集的最基础技能与常用工具的使用方法. 二.实践内容 1.各种搜索技巧的应用 2.DNS IP注册信息的查询 3.基本的扫描技术:主机发现.端口扫描.OS及服务版本探测.具体服务 ...

  3. Android性能测试之Monkey使用

    内容中包含 base64string 图片造成字符过多,拒绝显示

  4. Selenium自动化测试值环境搭建

    Selenium自动化测试之环境搭建 一.背景介绍 自动化测试近几年在测试领域很火,出去面试要是说不会自动化测试薪资都不好意思往高了要!很多公司做敏捷测试用到自动化,其他一些公司也是跟风,即使用不上自 ...

  5. [转载]WebDriver工作原理

    转载自:https://www.cnblogs.com/testermark/p/3546287.html WebDriver的工作原理:  在我们new一个WebDriver的过程中,Seleniu ...

  6. Android-应用性能测试

    参考了文章:http://www.cnblogs.com/mliangchen/p/5125114.html 问题一:使用真机在DDMS下,查看不到应用进程,logcat也不全 最后,只能使用Geny ...

  7. Vscode 格式化vue Template代码段

    1.安装 vetur 2.在User Setting中增加设置: "vetur.format.defaultFormatter.html": "js-beautify-h ...

  8. JSON定义及应用

    1 什么是JSON? JSON 指的是 JavaScript 对象表示法(JavaScript Object Notation) 是轻量级的文本数据交换格式,JSON 比 XML 更小.更快,更易解析 ...

  9. #leetcode刷题之路32-最长有效括号

    给定一个只包含 '(' 和 ')' 的字符串,找出最长的包含有效括号的子串的长度. 示例 1:输入: "(()"输出: 2解释: 最长有效括号子串为 "()"示 ...

  10. codeforces 979 C. Kuro and Walking Route

    C. Kuro and Walking Route time limit per test 2 seconds memory limit per test 256 megabytes input st ...