【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]$之间且为整数。你需要确定每个函数的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 最小割的更多相关文章
- CF434D Nanami's Power Plant 最小割
传送门 因为连距离限制的边的细节调了贼久QAQ 这个题和HNOI2013 切糕性质相同,都是有距离限制的最小割问题 对于每一个函数,用一条链记录变量\(x\)在不同取值下这个函数的贡献.对于一个\(x ...
- 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 ...
- CF434D Nanami's Power Plant
就是切糕那道题,首先对每个函数连一串,然后\(x_u\leq x_v+d\)这个条件就是\(u\)函数\(i\)取值连向\(v\)函数\(i-d\)取值边权为inf,然后答案就是最小割了. #incl ...
- CodeForces - 434D Nanami's Power Plant
Codeforces - 434D 题目大意: 给定一个长为n的序列,序列中的第i为上的值\(x_i\),序列第i位上的值\(x_i\in[l_i,r_i]\),价值为\(f_i(x_i)\),其中\ ...
- 【HDU 5855】Less Time, More profit(网络流、最小割、最大权闭合子图)
Less Time, More profit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/O ...
- UVA 10480 Sabotage (网络流,最大流,最小割)
UVA 10480 Sabotage (网络流,最大流,最小割) Description The regime of a small but wealthy dictatorship has been ...
- bzoj1565【NOI2009】植物大战僵尸(最小割)
题目描述 Plants vs. Zombies(PVZ)是最近十分风靡的一款小游戏.Plants(植物)和Zombies(僵尸)是游戏的主角,其中Plants防守,而Zombies进攻.该款游戏包含多 ...
- UVA10480:Sabotage(最小割+输出)
Sabotage 题目链接:https://vjudge.net/problem/UVA-10480 Description: The regime of a small but wealthy di ...
- 【二分 最小割】cf808F. Card Game
Digital collectible card games have become very popular recently. So Vova decided to try one of thes ...
随机推荐
- Ubuntu下实验安装
1.Ubuntu下安装sublime : http://www.linuxidc.com/Linux/2015-01/112137.htm 2.http://www.linuxidc.com/Linu ...
- SpringMVC知识点
一.SpringMVC 1.HelloWorld案例 ①步骤: 加jar包 在web.xml文件中配置DispatcherServlet 加入SpringMVC的配置文件 编写处理请求的处理器,并标识 ...
- JSP(1)—基础知识
JSP(1)-基本知识 起源 在很多动态网页中绝大多数网页都是固定不变的只有局部内容需要动态产生和改变,如果使用Servlet程序来输出只有局部内容需要动态改变的网页,其中所有的的静态内容,也需要程序 ...
- JSR 整理、翻译
https://jcp.org/en/jsr/all https://github.com/search?l=Java&q=JSR&type=Repositories
- Python计算分位数
Python计算分位数 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/gdkyxy2013/article/details/80911514 ...
- golang基础学习及web框架
golang的web框架 web框架百花齐放:对比 Go Web 编程 Go Web Examples Golang 适合做 Web 开发吗? beego beego简介 go-restful gol ...
- 简单了解weblogic配置文件
WebLogic的启动是通过启动文件来完成的 包括启动管理服务器(startWebLogic) 启动被管服务器(startManagedWebLogic) 设置域环境(setDomainEnv) 关闭 ...
- 用GO开发企业级分布式云存储系统
一.基础架构 二.开发工具
- 在netty3.x中存在两种线程:boss线程和worker线程。
在netty 3.x 中存在两种线程:boss线程和worker线程.
- Unable to find vcvarsall.bat
windows下pip安装各种包时,经常会遇到此错误.本文介绍解决方案. 第一步:安装visual studio 第二步:安装everything 打开everything,搜索vcvarsall.b ...