[luoguP2886] [USACO07NOV]牛继电器Cow Relays(矩阵)


传送门

矩阵快速幂,本质是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 矩阵
Copyright © 2002-2019 k262电脑网 www.k262.cn 皖ICP备2020016292号
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!QQ:251442993 热门搜索 网站地图