【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]$之间且为整数。你需要确定每个函数的x的取值,使得所有函数的函数值之和最大。还有m个限制,每条限制形如$u,v,d$,表示$x_u\le x_v+d$。求最大函数值之和。

$n\le 50,m\le 100,-100\le l_i\le r_i\le 100$

题解:傻逼了连切糕都忘了。

对于一个方程,我们把它的所有可能取值按照x从小到大串成一串,首尾分别与S和T相连,其中第i个点和第i+1个点的边的容量为当$x=l+i-1$时的函数值(由于可能存在负数,我们给每条边的权值都加上一个大数,最后再把这个大数减去)。对于限制u,v,d,我们从u中所有代表$x_u=i$的点向v中代表$x_v=i-d$的点连一条容量inf的边,便完成了限制。

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
const ll big=1ll<<30;
const ll inf=1ll<<50;
int n,m,tot,S,T,cnt;
ll ans;
int L[60],R[60],to[200010],nxt[200010],head[12000],d[12000];
int p[60][210];
ll val[200010],A[60],B[60],C[60];
queue<int> q;
inline void add(int a,int b,ll c)
{
to[cnt]=b,val[cnt]=c,nxt[cnt]=head[a],head[a]=cnt++;
to[cnt]=a,val[cnt]=0,nxt[cnt]=head[b],head[b]=cnt++;
}
ll dfs(int x,ll mf)
{
if(x==T) return mf;
int i;
ll temp=mf,k;
for(i=head[x];i!=-1;i=nxt[i]) if(val[i]&&d[to[i]]==d[x]+1)
{
k=dfs(to[i],min(temp,val[i]));
if(!k) d[to[i]]=-1;
temp-=k,val[i]-=k,val[i^1]+=k;
if(!temp) break;
}
return mf-temp;
}
inline int bfs()
{
while(!q.empty()) q.pop();
int i,u;
memset(d,0,sizeof(d));
q.push(S),d[S]=1;
while(!q.empty())
{
u=q.front(),q.pop();
for(i=head[u];i!=-1;i=nxt[i]) if(val[i]&&!d[to[i]])
{
d[to[i]]=d[u]+1;
if(to[i]==T) return 1;
q.push(to[i]);
}
}
return 0;
}
int main()
{
//freopen("cf434D.in","r",stdin);
scanf("%d%d",&n,&m);
S=0,T=tot=1;
int i,j,a,b,c;
memset(head,-1,sizeof(head));
for(i=1;i<=n;i++) scanf("%lld%lld%lld",&A[i],&B[i],&C[i]);
for(i=1;i<=n;i++)
{
scanf("%d%d",&L[i],&R[i]);
add(S,tot+1,inf);
for(j=L[i];j<=R[i];j++)
{
p[i][j-L[i]]=++tot;
add(tot,tot+1,big-(A[i]*j*j+B[i]*j+C[i]));
}
p[i][R[i]-L[i]+1]=++tot;
add(tot,T,inf);
}
for(i=1;i<=m;i++)
{
scanf("%d%d%d",&a,&b,&c);
for(j=max(L[b],L[a]-c);j<=min(R[b],R[a]-c)+1;j++)
{
add(p[a][j+c-L[a]],p[b][j-L[b]],inf);
}
}
while(bfs()) ans+=dfs(S,inf);
printf("%lld",big*n-ans);
return 0;
}

【CF434D】Nanami's Power Plant 最小割的更多相关文章

  1. CF434D Nanami's Power Plant 最小割

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

  2. 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 ...

  3. CF434D Nanami's Power Plant

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

  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. 【HDU 5855】Less Time, More profit(网络流、最小割、最大权闭合子图)

    Less Time, More profit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

  6. UVA 10480 Sabotage (网络流,最大流,最小割)

    UVA 10480 Sabotage (网络流,最大流,最小割) Description The regime of a small but wealthy dictatorship has been ...

  7. bzoj1565【NOI2009】植物大战僵尸(最小割)

    题目描述 Plants vs. Zombies(PVZ)是最近十分风靡的一款小游戏.Plants(植物)和Zombies(僵尸)是游戏的主角,其中Plants防守,而Zombies进攻.该款游戏包含多 ...

  8. UVA10480:Sabotage(最小割+输出)

    Sabotage 题目链接:https://vjudge.net/problem/UVA-10480 Description: The regime of a small but wealthy di ...

  9. 【二分 最小割】cf808F. Card Game

    Digital collectible card games have become very popular recently. So Vova decided to try one of thes ...

随机推荐

  1. zepto 选中select option 的值

    1,网上搜的,感觉蛮好用的,先存着 $('#sel').find('option').not(function() {return !this.selected;}).val();

  2. Application-Level层级异常捕获并定位程序的异常位置

    最近遇到一个需求,在设置503错误页面时,如果程序出错,服务器自动发邮件通知所有程序员,方便程序员及时解决问题. 想到好像global.cs文件里面好像有个erro事件,然后找到了Applicatio ...

  3. pygame-KidsCanCode系列jumpy-part17-mask-collide碰撞检测

    这节我们研究下pygame的几种碰撞检测模式: 如上图,左侧是默认的检测模式:基于矩形的检测(这也是性能最好的模式), 右侧是基于圆形的检测(性能略差于矩形检测). 矩形检测法虽然性能好,但是缺点也很 ...

  4. ACM-ICPC 2018 南京赛区网络预赛 E题

    ACM-ICPC 2018 南京赛区网络预赛 E题 题目链接: https://nanti.jisuanke.com/t/30994 Dlsj is competing in a contest wi ...

  5. Python3 与 NetCore 基础语法对比(Function专栏)

    Jupyter最新排版:https://www.cnblogs.com/dotnetcrazy/p/9175950.html 昨晚开始写大纲做demo,今天牺牲中午休息时间码文一篇,希望大家点点赞 O ...

  6. linux下的EDA——VCS使用

    原帖地址:https://blog.csdn.net/moon9999/article/details/75283926 在Linux下对verilogHDL进行功能仿真时非常必要的,下面提供两种常见 ...

  7. spring boot使用TestRestTemplate集成测试 RESTful 接口

    这篇文章没什么技术含量,只是单纯的记录一下如何用TestRestTemplate访问受security保护的api,供以后查阅. @Slf4j @RunWith(SpringRunner.class) ...

  8. zigw 和 nanoWatch, libudev.so 和 XMR 挖矿程序查杀记录

    最近这两天以来,服务器一致声音很响.本来以为有同事在运行大的程序,结果后来发现持续很长时间都是这样,并没有停的样子.后来查了一下,发现有几个可疑进程导致,干掉之后,果然服务器静悄悄了. 但是,问题并没 ...

  9. .NET 同步与异步 之 线程安全的集合 (十一)

    本随笔续接:.NET 同步与异步 之 警惕闭包(十) 无论之前说的锁.原子操作 还是 警惕闭包,都是为安全保驾护航,本篇随笔继续安全方面的主题:线程安全的集合. 先看一下命名空间:System.Col ...

  10. LaTeX中的各种距离设置总结

    LaTeX中的各种距离设置总结   1. 页面设置 A4 会给你一个较小的页面,为了使用更多的控制,可用 geometry宏包  和  命令 \layout . 2. 改变长度 在latex里改变长度 ...