hdu 2807(矩阵+floyed)】的更多相关文章

The Shortest Path Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2996    Accepted Submission(s): 980 Problem Description There are N cities in the country. Each city is represent by a matrix si…
http://acm.hdu.edu.cn/showproblem.php?pid=4291 凡是取模的都有循环节-----常数有,矩阵也有,并且矩阵的更奇妙: g(g(g(n))) mod 109 + 7  最外层MOD=1e9+7  能够算出g(g(n))的循环节222222224.进而算出g(n)的循环节183120LL.然后由内而外计算就可以 凝视掉的是求循环节的代码 //#pragma comment(linker, "/STACK:102400000,102400000")…
2021.11.03 P2886 [USACO07NOV]Cow Relays G(矩阵+floyed) [P2886 USACO07NOV]Cow Relays G - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 题意: 给出一张无向连通图,求S到E经过k条边的最短路. 分析: 对于floyed,在第k个点时,任意的i到j之间的最短路已经经过了(k-1)个点.当fa[i] [j]经过了x条边,fb[i] [j]经过了y条边,想要算出经过了x+y条边,只需要按照floyed的算…
The Shortest Path Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3164    Accepted Submission(s): 1030 Problem Description There are N cities in the country. Each city is represent by a matrix s…
http://acm.hdu.edu.cn/showproblem.php?pid=2807 第一次做矩阵乘法,没有优化超时,看了别人的优化的矩阵乘法,就过了. #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #define maxn 100 using namespace std; <<; int n,m,t1,x,y; int g[ma…
http://acm.hdu.edu.cn/showproblem.php?pid=2807 把矩阵相乘放在第二重循环,第三重循环只进行比较可以水过,优化的方法不懂 主要用这题练习floyd的写法 #include <iostream> #include <cstdio> using namespace std ; const int INF=0xfffffff ; int n,m ; ][] ; ][][],c[][] ; ][],][]) { int i,j,k ; ;i<…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2855 题目大意:求$S(n)=\sum_{k=0}^{n}C_{n}^{k}Fibonacci(k)$ 解题思路: 题目挺吓人的.先把完整组合数+Fibonacci展开来. 利用Fibonacci的特性,从第一项开始消啊消,消到只有一个数: $S(0)=f(0)$ $S(1)=f(2)$ $S(2)=f(4)$ $S(n)=f(2*n)$ 这样矩阵快速幂就可以了,特判$n=0$时的情况. 快速幂矩阵…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4471 解题思路,矩阵快速幂····特殊点特殊处理····· 令h为计算某个数最多须知前h个数,于是写出方程: D = c1 c2 ``` c[h-1] c[h] 1 0 ``` 0 0 0 1 ``` 0 0 0 0   0 0 0 0   1 0 V[x] = f[x] f[x-1] ` ` f[x-h+1] 显然有V[x+1] = D*V[x].D是由系数行向量,一个(h-1)*(h-1)的单…
HDU - 1575 题目: A为一个方阵,则Tr A表示A的迹(就是主对角线上各项的和),现要求Tr(A^k)%9973.  Input数据的第一行是一个T,表示有T组数据. 每组数据的第一行有n(2 <= n <= 10)和k(2 <= k < 10^9)两个数据.接下来有n行,每行有n个数据,每个数据的范围是[0,9],表示方阵A的内容. Output对应每组数据,输出Tr(A^k)%9973.Sample Input 2 2 2 1 0 0 1 3 99999999 1 2…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1757 题意不难理解,当x小于10的时候,数列f(x)=x,当x大于等于10的时候f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + …… + a9 * f(x-10); 所求的是f(x)取m的模,而x,m,a[0]至a[9]都是输入项 初拿到这道题,最开始想的一般是暴力枚举,通过for循环求出f(x)然后再取模,但是有两个问题,首先f(x)可能特别大,其…