// 差分约束系统
// 火烧连营
// n个点 m条边 每天边约束i到j这些军营的人数 n个兵营都有容量
// Si表示前i个军营的总数 那么 1.Si-S(i-1)<=C[i] 这里 建边(i-1,i) 权值为 C[i]
// 2.S(i-1)-Si<=0 这里 建边(i,i-1) 权值为 0
// 3.S(j)-S(i-1)>=k => S(i-1)-Sj<=-k 这里建边 (j,i-1) 权值为 -k
// 题目求的事 Sn-S0的最小值 Sn-S0>=m 中符合条件的m最大值就是答案
// 等价 S0-Sn<=-m 求点 Sn 到 S0的最小值 就是求最短路径 (这里可能不好理解,需要慢慢体会)
// #include <iostream>
#include <map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
#define MOD 1000000007
#define maxn 20010 // 开始我天真了 maxn=10010 和 m 差不错大 WA的好难过 图中边数应该为 m+2n
#define MAX 100000000
struct node{
int to;
int next;
int val;
}E[maxn];
int num;
int V[];
int C[];
int d[],cnt[];
bool f[];
bool sfpa(int s,int t){// s既表示起点 又表示节点个数
queue <int> Q;
int u,v;
int e;
Q.push(s);
d[s]=;
f[s]=true;
while(!Q.empty()){
u=Q.front(); Q.pop();
cnt[u]++;
if(cnt[u]>s) return false;
f[u]=false;
for(e=V[u];e!=-;e=E[e].next){
v=E[e].to;
if(d[u]+E[e].val<d[v]){
d[v]=d[u]+E[e].val;
if(!f[v])
{
f[v]=true;
Q.push(v);
}
}
}
}
return true;
}
int main(){
int i,j,k;
int n,m;
while(scanf("%d %d",&n,&m)!=EOF){
for(i=;i<=n;i++)
{
scanf("%d",&C[i]);
V[i]=-;
d[i]=MAX;
cnt[i]=;
f[i]=false;
}
num=;
i=;
V[i]=-;
d[i]=MAX;
cnt[i]=;
f[i]=false;
while(m--){
scanf("%d %d %d",&i,&j,&k);
E[num].to=i-;
E[num].val=-k;
E[num].next=V[j];
V[j]=num++;
}
for(i=n;i>=;i--){
E[num].to=i;
E[num].val=C[i];
E[num].next=V[i-];
V[i-]=num++;
E[num].to=i-;
E[num].val=;
E[num].next=V[i];
V[i]=num++;
}
if(sfpa(n,))
printf("%d\n",-d[]);
else
printf("Bad Estimations\n"); } }

zoj 2770 Burn the Linked Camp (差分约束系统)的更多相关文章

  1. ZOJ 2770 Burn the Linked Camp 差分约束

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemCode=2770 Burn the Linked Camp Time Limi ...

  2. ZOJ 2770 Burn the Linked Camp 差分约束 ZOJ排名第一~

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1770 题目大意: 陆逊为了火烧连营七百里,派出了间谍刺探敌情,得之刘备的军营以 ...

  3. zoj 2770 Burn the Linked Camp

    今天刚刚学差分约束系统.利用最短路求解不等式.世界真的好奇妙!感觉不等式漏下几个会导致WA!! #include<cstdio> #include<cstring> #incl ...

  4. ZOJ 2770 Burn the Linked Camp(spfa&&bellman)

    //差分约束 >=求最长路径 <=求最短路径 结果都一样//spfa#include<stdio.h> #include<string.h> #include< ...

  5. zoj2770 Burn the Linked Camp --- 差分约束

    有n个营地,每一个营地至多容纳Ci人.给出m个条件:第i到第j个营地之间至少有k人. 问n个营地总共至少有多少人. 此题显然差分约束.要求最小值.则建立x-y>=z方程组,建图求最长路. 用d[ ...

  6. Burn the Linked Camp(bellman 差分约束系统)

    Burn the Linked Camp Time Limit: 2 Seconds      Memory Limit: 65536 KB It is well known that, in the ...

  7. zoj Burn the Linked Camp (查分约束)

    Burn the Linked Camp Time Limit: 2 Seconds      Memory Limit: 65536 KB It is well known that, in the ...

  8. ZOJ2770 Burn the Linked Camp(差分约束系统)

    区间和一定要联系到前缀和. 这题,把前缀和看作点,从s0到sn: 对于每一个营地i的容量capi,有这么个关系si-si-1<=capi: 对于每一个区间的评估i,j,k,有sj-si-1> ...

  9. ZOJ 2770 差分约束+SPFA

    Burn the Linked Camp Time Limit: 2 Seconds      Memory Limit: 65536 KB It is well known that, in the ...

随机推荐

  1. OD鲜为人知的小技巧--搜索通配符(关键字)

    我看过一些OD教程,关于通配符这一点很少有人讲解(大概是我看的教程少吧)  近日通过看<黑客反汇编揭秘(第二版)>第165页了解到,原来OD还有这样方便的功能,那就是搜索通配符: Olly ...

  2. 15个实用的jQuery技术

    JQuery是目前最流行的JavaScript框架之一,可以显著的提高用户与网络应用的交互. 今天为大家介绍50有用的jQuery技术: 1.移动Box 2.滑动框和标题 3.数据的可视化:使用HTM ...

  3. Ubuntu下非常给力的下载工具--uget+aria2

    转自Ubuntu下非常给力的下载工具--uget+aria2 Windows下的下载工具--迅雷,之所以下载速度快,乃是它能搜索资源.为己所用,而不是仅仅从原始地址这单一资源处下载. Ubuntu下也 ...

  4. 【hadoop2.6.0】MapReduce原理

    看了几篇博文,感觉还是云里雾里的. http://blog.csdn.net/opennaive/article/details/7514146 http://www.aboutyun.com/thr ...

  5. React-Native学习指南

    React-Native学习指南 本指南汇集React-Native各类学习资源,给大家提供便利.指南正在不断的更新,大家有好的资源欢迎Pull Requests! 同时还有Awesome React ...

  6. gulp下livereload和webserver实现本地服务器下文件自动刷新

    一.前言 node从v0.10.26升级(为了匹配autoprefixer)到v5.3.0后出现了gulp插件兼容问题,在nodejs下各种新的插件出现问题,需要重新配置.livereload实现ch ...

  7. **bootstrap常见常用样式总结

    1.水平居中 用 .text-center 类

  8. POJ 3270 Cow Sorting(置换群)

    题目链接 题意 : N头牛,每个牛的坏脾气都有一个值,每个值都不相同,把这个值按照从小到大排序,如果两个值交换,那么会花掉这两个值之和的时间,让你花最少的时间将每个值从小到大排好序,求最小的总时间. ...

  9. hdu 4418 Time travel 概率DP

    高斯消元求期望!! 将n时间点构成2*(n-1)的环,每一点的期望值为dp[i]=dp[i+1]*p1+dp[i+2]*p2+……+dp[i+m]*pm+1. 这样就可以多个方程,利用高斯消元求解. ...

  10. 【转】Android 实现“再按一次退出程序”

    From:http://blog.csdn.net/ldj299/article/details/7574365 个人觉得当用户按下后退键时,出现"再按一次退出"的提示防止误操作比 ...