区间和一定要联系到前缀和。

  1. 这题,把前缀和看作点,从s0到sn;
  2. 对于每一个营地i的容量capi,有这么个关系si-si-1<=capi
  3. 对于每一个区间的评估i,j,k,有sj-si-1>=k,即si-1-sj<=k;
  4. 接下来就是连边了,对于v<=u+w由u向v连权w的边,超级源向n+1个点连权0的边。
  5. 最后跑SPFA,如果出现负环则无解;而有解的话,所求答案就在d[sn]里,不过因为题目的前缀和是非负整数且要求的最少,所以就要让d中所有数都同时加上合适的数得到另一个真正所求的解。
 #include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
#define INF (1<<30)
#define MAXN 1111
#define MAXM 22222 struct Edge{
int v,cost,next;
}edge[MAXM];
int head[MAXN],NE;
void addEdge(int u,int v,int cost){
edge[NE].v=v; edge[NE].cost=cost; edge[NE].next=head[u];
head[u]=NE++;
} int n,m,d[MAXN],cnt[MAXN];
bool vis[MAXN];
bool SPFA(){
for(int i=; i<=n; ++i){
vis[i]=; cnt[i]=; d[i]=INF;
}
vis[n+]=; cnt[n+]=; d[n+]=;
queue<int> que;
que.push(n+);
while(!que.empty()){
int u=que.front(); que.pop();
if(cnt[u]>n+) return ;
for(int i=head[u]; i!=-; i=edge[i].next){
int v=edge[i].v;
if(d[v]>d[u]+edge[i].cost){
d[v]=d[u]+edge[i].cost;
if(!vis[v]){
vis[v]=;
++cnt[v];
que.push(v);
}
}
}
vis[u]=;
}
return ;
}
int main(){
int a,b,c,cap[MAXN];
while(~scanf("%d%d",&n,&m)){
for(int i=; i<=n; ++i) scanf("%d",cap+i); memset(head,-,sizeof(head));
NE=;
for(int i=; i<=n; ++i) addEdge(i-,i,cap[i]);
for(int i=; i<=n; ++i) addEdge(n+,i,);
while(m--){
scanf("%d%d%d",&a,&b,&c);
addEdge(b,a-,-c);
}
if(SPFA()){
int tmp=INF;
for(int i=; i<=n; ++i) tmp=min(tmp,d[i]);
if(tmp<) d[n]-=tmp;
printf("%d\n",d[n]);
}else puts("Bad Estimations");
}
return ;
}

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

  1. zoj 2770 Burn the Linked Camp (差分约束系统)

    // 差分约束系统// 火烧连营 // n个点 m条边 每天边约束i到j这些军营的人数 n个兵营都有容量// Si表示前i个军营的总数 那么 1.Si-S(i-1)<=C[i] 这里 建边(i- ...

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

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

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

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

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

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

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

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

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

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

  7. zoj 2770 Burn the Linked Camp

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

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

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

  9. zoj2770 差分约束系统

    zoj1770  x1- x2 <= t1 x3 - x5 <= t2 x2 - x3 <= t3 .... 可以用最短路的方法来求的解. 最短路的松弛操作,和这些式子很相近. 如果 ...

随机推荐

  1. Python列表基础

    ==========列表基础=========== 列表中的数据是可以被修改的.字典,元组,集合是不能被修改的. >>> li1=['3edf','dafdas'] >> ...

  2. OpenSwitch操作系统成为Linux基金会官方项目

    导读 非盈利机构Linux基金会为推进Linux和开源软件在企业和专业人士的发展,于今天宣布OpenSwitch项目成为Linux基金会官方项目之一. Linux基金会的常务董事Jim Zemlin表 ...

  3. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  4. 谷歌浏览器 DEV Tools

    谷歌浏览器如今是Web开发者们所使用的最流行的网页浏览器.伴随每六个星期一次的发布周期和不断扩大的强大的开发功能,Chrome变成了一个必须的工具.大多数可能熟悉关于chorme的许多特点,例如使用c ...

  5. map遍历

    Set<Map.Entry<String,String>> ss = params.entrySet(); for(Map.Entry<String,String> ...

  6. pro git 使用积累

    http://www.zhihu.com/question/20070065 git相关问题的收集 Git 是 Linux 之父 Linus Trovalds,为管理 Linux 内核代码而建立的,被 ...

  7. 【Python】Django 时间字段 最佳实践

    . python datetime from datetime import datetime datetime.now() datetime.utcnow() from datetime impor ...

  8. HDFS 原理、架构与特性介绍--转载

    原文地址:http://www.uml.org.cn/sjjm/201309044.asp 本文主要讲述 HDFS原理-架构.副本机制.HDFS负载均衡.机架感知.健壮性.文件删除恢复机制 1:当前H ...

  9. 【转】基于注解的SpirngMVC简单介绍

    转载地址:http://haohaoxuexi.iteye.com/blog/1343761 SpringMVC是一个基于DispatcherServlet的MVC框架,每一个请求最先访问的都是 Di ...

  10. 【USACO】numtri

    给一颗数字树,让找一条数字和最大的路径.一下子就想起刚学不久的回溯法了.照着写了个代码,调了调搞通了.在小数据的情况下是对的,但是在test 6 树有199层的时候溢出了. #include < ...