【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. linux操作之逻辑分区与交换分区篇

    作业一: 1)   开启Linux系统前添加一块大小为15G的SCSI硬盘 2)   开启系统,右击桌面,打开终端 3)   为新加的硬盘分区,一个主分区大小为5G,剩余空间给扩展分区,在扩展分区上划 ...

  2. sql 2008 查询性能优化笔记

    索引: set statistics io on select p.productID,p.name,p.Weight,p.StandardCost from production.product p ...

  3. 常见问题1:默认div隐藏,点击按钮时出现,再点击时隐藏。

    例:默认div隐藏,点击按钮时出现,再点击时隐藏. <a href="#" onclick="f('ycbc')"; >控制按钮</a> ...

  4. Python3 与 NetCore 基础语法对比(List、Tuple、Dict、Set专栏)

    Jupyter最新版:https://www.cnblogs.com/dotnetcrazy/p/9155310.html 在线演示:http://nbviewer.jupyter.org/githu ...

  5. C# Monitor实现

    Monitor的code如下,非常简单: public static class Monitor { public static extern void Enter(Object obj); publ ...

  6. SSH + Google Authenticator 安全加固

    1. SSH连接 Secure Shell(安全外壳协议,简称SSH)是一种加密的网络传输协议,可在不安全的网络中为网络服务提供安全的传输环境.SSH通过在网络中创建安全隧道来实现SSH客户端与服务器 ...

  7. EAS开发之挂菜单

        一:以管理员账号登录   二:挂菜单     点击菜单栏"系统"——客户化菜单编辑——选中上级目录——点击 新建——命名.键入唯一编码,把ui.java类的全路径,拷贝到 ...

  8. webstorm11.0下载地址和webstorm11.0破解程序patcher.exe下载使用方法说明 前端IDE工具的利器

    20160107以下亲测可行. webstorm11.0下载地址:http://www.fxxz.com/soft/109234.html webstorm11.0下载安装破解使用说明: 下载完Web ...

  9. v2ray和ss的安装资料整理

    v2ray: 1. https://yuan.ga/v2ray-complete-tutorial/ 2. https://toutyrater.github.io/ 推荐使用:v2ray,会比ss快 ...

  10. Centos-7.x 下子网掩码的配置

    [背景] 今天在自己的虚拟机上安装上了centos-7.6操作系统,应该是安装的过程中大意了:安装完成后虚拟机可以正常访问外网但是 我的笔记本连接不上虚拟机. 笔记本的IP地址:172.16.192. ...