zoj2770
来源:互联网 发布:小米手机自动更新软件 编辑:程序博客网 时间:2024/05/15 15:36
//bellman 算法,主要是可以判断是不是有负权回路;
//差分约束的问题
#include<iostream>#include<string.h>#include<cmath>#include<stdio.h>using namespace std;#define inf 0x7ffffff#define maxn 23000int dist[maxn];int c[maxn];int d[maxn];int ei;int n,m;struct eg{ int u; int v; int w;}edges[maxn];void init(){ ei=0; int i; for(i=0;i<=n;i++) { dist[i]=inf; } d[0]=0; dist[n]=0;}bool bellman(){ int i,k,t; for(i=0;i<n;i++) { for(k=0;k<ei;k++) { t=dist[edges[k].u]+edges[k].w; if(dist[edges[k].u]!=inf&&t<dist[edges[k].v]) { dist[edges[k].v]=t; } } } for(k=0;k<ei;k++)//判断是不是有负权回路 { if(dist[edges[k].u]!=inf&&dist[edges[k].u]+edges[k].w<dist[edges[k].v]) return false; } return true;}int main(){ while(scanf("%d%d",&n,&m)!=EOF) { init(); int i,u,v,w; for(i=1;i<=n;i++)//一些不等式 { scanf("%d",&c[i]); edges[ei].u=i-1; edges[ei].v=i; edges[ei].w=c[i]; ei++; edges[ei].u=i; edges[ei].v=i-1; edges[ei].w=0; ei++; d[i]=c[i]+d[i-1]; } for(i=0;i<m;i++) { scanf("%d%d%d",&u,&v,&w); edges[ei].u=v; edges[ei].v=u-1; edges[ei].w=-w; ei++; edges[ei].u=u-1; edges[ei].v=v; edges[ei].w=d[v]-d[u-1]; ei++; } if(!bellman()) printf("Bad Estimations\n"); else printf("%d\n",dist[n]-dist[0]); } return 0;}
0 0
- ZOJ2770
- ZOJ2770
- zoj2770
- ZOJ2770 差分约束
- zoj2770 差分约束
- Bellman算法ZOJ2770
- zoj2770,差分约束系统
- zoj2770解题报告(差分约束)
- ZOJ2770,火烧连营,差分约束
- 差分约束入门题ZOJ2770&&AOJ517
- ZOJ2770 Burn the Linked Camp,差分约束
- ZOJ2770-Burn the Linked Camp(差分约束系统)
- zoj2770 Burn the Linked Camp --- 差分约束
- ZOJ2770 Burn the Linked Camp(差分约束)
- zoj2770(差分约束)火烧连营
- ZOJ2770:Burn the Linked Camp(差分约束)
- zoj2770 Burn the Linked Camp 差分约束和最短路bellman
- ZOJ2770 Burn the Linked Camp (差分约束与最短路)
- Oracle数字处理函数
- 恶意抢注商标事件层出 国内知识产权保护堪忧
- 极速购吧---天天九块九包邮
- Centos下报“is not in the sudoers file”错误
- top命令
- zoj2770
- 一种利用js实现的仿淘宝商品评价功能的方法
- 为什么读研
- IOS8 alertView 和 actionSheet 使用方法
- 【Boost】boost库asio详解5——resolver与endpoint使用说明
- 贪心算法介绍
- 数据库多表连接,返回结果集
- 两段shell脚本,监控进程和主动结束进程
- Git---强大的版本控制工具