【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 ...
随机推荐
- Compile groovy mixed with java in Maven
Assuming that groovy codes are in src/main/groovy and java codes are in src/main/java. We can use 2 ...
- 【数位dp】Beautiful Numbers @2018acm上海大都会赛J
目录 Beautiful Numbers PROBLEM 题目描述 输入描述: 输出描述: 输入 输出 MEANING SOLUTION CODE Beautiful Numbers PROBLEM ...
- 12 week blog
调用一个地图(百度地图)API(定位) 到网站: 1.调用API的js : <script type="text/javascript" src="https:// ...
- 2018年东北农业大学春季校赛 E-wyh的阶乘(求n!的0的个数)
链接:https://www.nowcoder.com/acm/contest/93/E来源:牛客网 题目描述 这个问题很简单,就是问你n的阶乘末尾有几个0? 输入描述: 输入第一行一个整数T(1&l ...
- nginx配置http访问自动跳转到https
1.按照如下格式修改nginx.conf 配置文件,80端口会自动转给443端口,这样就强制使用SSL证书加密了.访问http的时候会自动跳转到https上面 server { listen ; se ...
- Mac PD 虚拟机 鼠标双击 输入 "c" 解决
Mac PD 虚拟机 鼠标双击 输入 "c" 解决 特么的, 是屏幕取词软件引起的.. 关闭就好了.
- C# System.Threading.AutoResetEvent
表示线程同步事件在一个等待线程释放后收到信号时自动重置. using System; using System.Threading; // Visual Studio: Replace the def ...
- 【PMP】关键路径法与关键链法
通俗理解 关键路径法:把项目上的资源都事先全部分到每个活动上. 关键链法:每个活动不打富余,项目经理自己掌握资源,哪个成员执行过程中遇到困难,再给他单独分配资源. PMBOK定义 关键路径法:关键路径 ...
- AngularJS 使用ng-repeat报错
[ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify uniq ...
- mac 使用笔记日志
telnet安装 安装homebrew /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/i ...