传送门
矩阵快速幂,本质是floyd
把 * 改成 + 即可
注意初始化
因为只有100条边,所以可以离散化
#include <cstdio> #include <cstring> #include <algorithm> #define N 101 #define min(x, y) ((x) < (y) ? (x) : (y)) int n, t, s, e, cnt; int x[N], y[N], z[N], a[N]; struct Matrix }; inline Matrix operator * (Matrix x, Matrix y) inline Matrix operator ^ (Matrix x, int y) return ans; } int main() std::sort(a + 1, a + cnt + 1); cnt = std::unique(a + 1, a + cnt + 1) (a + 1); sum.n = sum.m = cnt; for(i = 1; i <= t; i++) sum = sum ^ n; s = std::lower_bound(a + 1, a + cnt + 1, s) a; e = std::lower_bound(a + 1, a + cnt + 1, e) a; printf("%d\n", sum.a[s][e]); return 0; }
上一篇:[BZOJ2342] [Shoi2011]双倍回文(manacher)
下一篇:[luoguP2073] 送花(set)
矩阵 DP









