传送门

令前缀和为s[i],则⼀一个要求等价于 s[r] - s[l - 1] >= x。

题中还有别的要求,包括 s[i] - s[i - 1] <= 1 和 s[i] - s[i- 1] >= 0。

建一个超级原点s,把所有结点连到s(令s = n + 1)

差分约束系统规定的只是元素的相对关系

按照题意,相对关系不变时最后的答案尽可能小

因此最终答案应该是:dis[ n ] - min_dis

#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std; inline int read()
{
int sum = ,p = ;
char ch = getchar();
while(ch < '' || ch > '')
{
if(ch == '-')
p = -;
ch = getchar();
}
while(ch >= '' && ch <= '')
{
(sum *= ) += ch - '';
ch = getchar();
}
return sum * p;
} const int maxn = ,maxm = ;
int n,m,s,cnt;
int dis[maxn],head[maxn];
bool vis[maxn];
struct edge
{
int nxt,to,wei;
} e[maxn * ]; void add(int x,int y,int z)
{
e[++cnt].nxt = head[x];
e[cnt].to = y;
e[cnt].wei = z;
head[x] = cnt;
} void spfa(int x)
{
queue<int> q;
q.push(x);
for(int i = ; i <= n + ; i ++)
dis[i] = 1e9;
dis[s] = ;
vis[s] = true;
while(!q.empty())
{
int o = q.front();
q.pop();
vis[o] = false;
for(int i = head[o]; i; i = e[i].nxt)
{
int v = e[i].to;
if(dis[v] > dis[o] + e[i].wei)
{
dis[v] = dis[o] + e[i].wei;
if(!vis[v])
{
q.push(v);
vis[v] = true;
}
}
}
}
} int main()
{
n = read(),m = read();
s = n + ;
memset(head,-,sizeof(head));
for(int i = ; i <= n; i++)
add(s,i,);
int a,b,c;
for(int i = ; i <= m; i++)
{
a = read(),b = read(),c = read();
add(b,a - ,-c);
}
for(int i = ; i <= n; i++)
{
add(i - ,i,);
add(i,i - ,);
}
spfa(s);
int ans = 1e9;
for(int i=; i<=n; i++)
ans = min(ans, dis[i]);
printf("%d",dis[n] - ans);
return ;
}

最新文章

  1. struts---JSP界面验证码生成与验证
  2. Java重点之小白解析--浅谈HashMap与HashTable
  3. jQuery构造函数init参数分析(三)
  4. 内嵌DB
  5. C# 6新特性及示例代码
  6. [vsftp服务]——ftp虚拟用户、权限设置等的实验
  7. jquery操作cookie {分享}
  8. HTML5_用语义化标记重新定义博客
  9. 【转】#ifdef __cplusplus深度剖析
  10. [jQuery] $.grep使用
  11. plaidctf2015 uncorrupt png
  12. poj3280(区间dp)
  13. 百度官方wormHole后门检测记录(转)
  14. 【杂】指针,*,&amp;
  15. python笔记10-切片(从list或字符串中取几个元素)
  16. C++ 重载运算符和重载函数
  17. 如何查看目前正在使用的Windows10是哪个版本?
  18. OpenEXR-2.2.0在Win7 x64系统下的安装方法
  19. SQL删除重复数据只保留一条数据
  20. Elasticsearch技术解析与实战(二)文档的CRUD操作

热门文章

  1. vs code使用指南
  2. 16day 路径信息系列
  3. g++运行c++程序提示main()找不到
  4. 编码 - 坑 - win10 下采用 utf-8, 导致 gitbash 中文字体异常, 待解决
  5. [NOI2014] 魔法森林 - Link Cut Tree
  6. 在 linux 上运行 oracle sql脚本
  7. c数据结构 -- 链表的理解
  8. Mysql使用事务
  9. 手写基于Promise A+规范的Promise
  10. 如何转proto