HDU 2994 Ant on the graph
来源:互联网 发布:网络招聘网站 编辑:程序博客网 时间:2024/05/15 04:07
将矩阵运算中的
论文记得好像是在cf的某个链接里下的,懒得上传直接放wiki链接好了。
Max-plus algebra
求
#include<algorithm>#include<iostream>#include<cstring>#include<cstdio>//-Container//-using namespace std;typedef long long ll;#define clr(a) memset(a,0,sizeof(a))const ll inf=100000000000000;int n,L,R;struct mt{ll e[50][50];};mt _mul(mt a,mt b){ int i,j,k;mt c;for(i=0;i<n;++i)for(j=0;j<n;++j)for(c.e[i][j]=-inf,k=0;k<n;++k)if(a.e[i][k]!=-inf&&b.e[k][j]!=-inf) c.e[i][j]=max(c.e[i][j],a.e[i][k]+b.e[k][j]); return c;};mt _qni(mt a,ll k){ int i,j;mt c;for(i=0;i<n;++i)for(j=0;j<n;++j)c.e[i][j]=-inf; for(i=0;i<n;++i)c.e[i][i]=0; for(;k;k>>=1,a=_mul(a,a))if(k&1)c=_mul(c,a); return c;};bool cl(){ int i,j,k,d;if(scanf("%d %d %d",&n,&L,&R)==-1)return 0; mt a;for(i=0;i<n;++i)for(j=0;j<n;++j){ scanf("%I64d",&a.e[i][j]);if(a.e[i][j]==-500)a.e[i][j]=-inf; } mt b=_qni(a,L);a.e[n-1][n-1]=0;mt c=_qni(a,R-L); b=_mul(b,c); if(b.e[0][n-1]==-inf)printf("IMPOSSIBLE\n"); else printf("%I64d\n",b.e[0][n-1]); return 1;};int main(){#ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);#endif while(cl()); return 0;};
阅读全文
0 0
- HDU 2994 Ant on the graph
- HDU 4677 Query on Graph
- hdu 4677 Query on Graph
- Random Walks on the Click Graph
- Graph Cuts on the GPU解析
- HDU 1252 Hike on a Graph
- 【HDU】4677 Query on Graph 动态树
- hdu 1252 Hike on a Graph(bfs)
- HDU 1252Hike on a Graph
- CodeForces 29D Ant on the Tree
- 【HDU】 5302 Connect the Graph【构造】
- hdu 5302 Connect the Graph(构造)
- HDU 5302(Connect the Graph- 构造)
- HDU 5302 Connect the Graph (构造)
- The Shortest Path in Nya Graph HDU
- The Shortest Path in Nya Graph HDU
- CUDA Cuts: Fast Graph Cuts on the GPU
- CUDA Cuts: Fast Graph Cuts on the GPU
- Modbus名词解释
- Android.mk高级写法
- cglib代理
- 阅读UGUI源码 零
- 22_栈的压入、弹出序列
- HDU 2994 Ant on the graph
- Android studio 生成二维码与扫描二维码
- java——引用类型参数传递
- 使用Intellij创建第一个Springboot程序
- 循环冗余校验编码(CRC校验码)介绍以及编程源代码
- vagrant up 启动时报错 Could not find Host Interface Networking driver! Please reinstall
- 堆的实现以及优先级队列
- docker国内镜像设置
- arch linux python3.6.2 import matplotlib.pyplot as plt 报错