就是切糕那道题,首先对每个函数连一串,然后\(x_u\leq x_v+d\)这个条件就是\(u\)函数\(i\)取值连向\(v\)函数\(i-d\)取值边权为inf,然后答案就是最小割了。

#include<bits/stdc++.h>
#define il inline//
#define vd void
typedef long long ll;
il int gi(){
int x=0,f=1;
char ch=getchar();
while(!isdigit(ch)){
if(ch=='-')f=-1;
ch=getchar();
}
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return x*f;
}
int a[51],b[51],c[51],l[51],r[51];
int num[51][202],cnt,S,T;
int fir[11000],head[10010],dep[10010],dis[10000010],nxt[10000010],id=1;
ll w[10000010];
il vd link(int a,int b,ll c){
nxt[++id]=fir[a],fir[a]=id,dis[id]=b,w[id]=c;
nxt[++id]=fir[b],fir[b]=id,dis[id]=a,w[id]=0;
}
il bool BFS(){
static int que[11000],hd,tl;
memset(dep,0,sizeof dep);
hd=tl=0;que[tl++]=S;dep[S]=1;
while(hd^tl){
int x=que[hd++];
for(int i=fir[x];i;i=nxt[i])
if(!dep[dis[i]]&&w[i])
dep[dis[i]]=dep[x]+1,que[tl++]=dis[i];
}
return dep[T];
}
il ll Dinic(int x,ll maxflow){
if(x==T)return maxflow;
ll ret=0;
for(int&i=head[x];i;i=nxt[i])
if(w[i]&&dep[dis[i]]==dep[x]+1){
ll d=Dinic(dis[i],std::min(maxflow-ret,w[i]));
w[i]-=d,w[i^1]+=d,ret+=d;
if(ret==maxflow)break;
}
return ret;
}
int main(){
int n=gi(),m=gi();S=++cnt,T=++cnt;
for(int i=1;i<=n;++i)a[i]=gi(),b[i]=gi(),c[i]=gi();
for(int i=1;i<=n;++i)l[i]=gi(),r[i]=gi();
for(int i=1;i<=n;++i){
for(int j=l[i];j<=r[i]+1;++j)num[i][j+100]=++cnt;
link(S,num[i][l[i]+100],1e18);
for(int j=l[i];j<=r[i];++j)link(num[i][j+100],num[i][j+101],(1<<25)-(a[i]*j*j+b[i]*j+c[i]));
link(num[i][r[i]+101],T,1e18);
}
int u,v,d;
while(m--){
u=gi(),v=gi(),d=gi();
for(int i=std::max(l[u]-d,l[v])+100;i<=std::min(r[u]-d,r[v])+101;++i)link(num[u][i+d],num[v][i],1e18);
}
ll ans=(1ll<<25)*n;
while(BFS())memcpy(head,fir,sizeof head),ans-=Dinic(S,1e18);
printf("%lld\n",ans);
return 0;
}

CF434D Nanami's Power Plant的更多相关文章

  1. CF434D Nanami's Power Plant 最小割

    传送门 因为连距离限制的边的细节调了贼久QAQ 这个题和HNOI2013 切糕性质相同,都是有距离限制的最小割问题 对于每一个函数,用一条链记录变量\(x\)在不同取值下这个函数的贡献.对于一个\(x ...

  2. 【CF434D】Nanami's Power Plant 最小割

    [CF434D]Nanami's Power Plant 题意:有n个二次函数$y=a_ix^2+b_ix+c_i$($a_i,b_i,c_i$是整数),第i个函数要求x的取值在$[l_i,r_i]$ ...

  3. Codeforces Round #248 (Div. 1) D - Nanami's Power Plant 最小割

    D - Nanami's Power Plant 思路:类似与bzoj切糕那道题的模型.. #include<bits/stdc++.h> #define LL long long #de ...

  4. CodeForces - 434D Nanami's Power Plant

    Codeforces - 434D 题目大意: 给定一个长为n的序列,序列中的第i为上的值\(x_i\),序列第i位上的值\(x_i\in[l_i,r_i]\),价值为\(f_i(x_i)\),其中\ ...

  5. 缩点:Power Plant;

    题目传送门:[UVALive 6437]Power Plant 题目大意:T组数据,给定一幅带权图(n, m), 然后给定k个点, 与图中存在有若干条边.每个点都要至少要和这k个点的一个点直接或间接相 ...

  6. Nuclear Power Plant ZOJ - 3840 树形dp

    There are N (1 ≤ N ≤ 105) cities on land, and there are N - 1 wires connecting the cities. Therefore ...

  7. UVA Live 6437 Power Plant 最小生成树

    题意: 有许多油井和村庄什么的,让你使得这些村庄能连通一个油井就好了.第一行给你一个数字T代表有T组测试数据,第二行有 M , N , K ,M代表包括油井在内的村庄数,N 代表有N个 两两连通的地方 ...

  8. LA 6437 Power Plant (prim最小生成树)

    还是裸的最小生成树 #include<bits/stdc++.h> using namespace std; int T,N,M,P,K,a,b,c; int dist[1020],m[1 ...

  9. Codeforce 水题报告(2)

    又水了一发Codeforce ,这次继续发发题解顺便给自己PKUSC攒攒人品吧 CodeForces 438C:The Child and Polygon: 描述:给出一个多边形,求三角剖分的方案数( ...

随机推荐

  1. 团队项目第二阶段个人进展——Day1

    一.昨天工作总结 冲刺第一天,查看了第一阶段的代码 二.遇到的问题 写个的代码发现看不懂了 三.今日工作规划 重新设计页面布局

  2. AWS CSAA -- 04 AWS Object Storage and CDN - S3 Glacier and CloudFront(三)

    021 Storage Gateway 022 Snowball 023 Snowball - Lab 024 S3 Transfer Acceleration

  3. eclipse neon配置tomcat8无法显示默认页面解决方法

    下载对应tomcat8版本到本地后,在eclipse中添加tomcat8的对应目录,输入http://localhost:8080时无法显示tomcat的index.jsp页面(会显示404页面).原 ...

  4. 学习笔记:Analyze MySQL Performance及慢日志的开启

    Table of Contents Analyze MySQL PerformanceTuningSlow queries and Slowlog Brought to you by Rick Jam ...

  5. python 多进程和子进程1

    多进程的缓冲区 #多进程 process.py from multiprocessing import Process,current_process import time def func1(): ...

  6. CentOS7 配置静态 ip

    1. 为 CentOS7 配置静态 ip 1.1 修改文件/etc/sysconfig/network-scripts/ifcfg-ens33 sudo vi /etc/sysconfig/netwo ...

  7. 记录一次mysql使用load into命令导入csv格式数据的过程

    今天从qwiklab实验获取一组数据,大概有5万条,在qwiklab实验室使用的是pgsql数据库,但是今天想把他插入本地的mysql数据库中. 1.首先是查看一下数据内容: 数据中有的是空值,有的是 ...

  8. 读高性能JavaScript编程 第一章

    草草的看完第一章,虽然看的是译文也是感觉涨姿势了, 我来总结一下: 由于 大多数浏览器都是 single process 处理 ui updatas and js execute 于是产生问题: js ...

  9. selenium3 浏览器驱动下载及验证

    下载浏览器驱动 当selenium升级到3.0之后,对不同的浏览器驱动进行了规范.如果想使用selenium驱动不同的浏览器,必须单独下载并设置不同的浏览器驱动. 各浏览器下载地址: Firefox浏 ...

  10. Swift Package Manager(一)初探

    一句话:Swift Package Manager(swift包管理器,简称:SPM)就是在swift开发中用来替代CocoaPod的:在swift开发中,SPM完全可以替代CocoaPod的功能,并 ...