CF1146G Zoning Restrictions
CF1146G Zoning Restrictions
网络流
h<=50?
直接都选择最大的,ans=n*h*h
最小割
考虑舍弃或者罚款
有一个>x就要罚款?
经典取值限制的模型:切糕割!
每个位置的x+1到额外点tot连接inf边
tot向t连接c边
大概这样:
#include<bits/stdc++.h> #define reg register int #define il inline #define fi first #define se second #define mk(a,b) make_pair(a,b) #define numb (ch^'0') #define pb push_back #define solid const auto & #define enter cout<<endl #define pii pair<int,int> using namespace std; typedef long long ll; template<class T>il void rd(T &x){char ch;x=0;bool fl=false;while(!isdigit(ch=getchar()))(ch=='-')&&(fl=true);for(x=numb;isdigit(ch=getchar());x=x*10+numb);(fl==true)&&(x=-x); } template<class T>il void output(T x){if(x/10)output(x/10);putchar(x%10+'0');} template<class T>il void ot(T x){if(x<0) putchar('-'),x=-x;output(x);putchar(' ');} template<class T>il void prt(T a[],int st,int nd){for(reg i=st;i<=nd;++i) ot(a[i]);putchar('\n');}namespace Miracle{ const int N=55; const int P=N*N; const int inf=0x3f3f3f3f; int n,m,h; int s,t; struct node{int nxt,to;int w; }e[2*(P+P+N*N)]; int hd[P],cnt=1; void add(int x,int y,int z){e[++cnt].nxt=hd[x];e[cnt].to=y;e[cnt].w=z;hd[x]=cnt;e[++cnt].nxt=hd[y];e[cnt].to=x;e[cnt].w=0;hd[y]=cnt; } int d[P]; int q[P],l,r; int ans; int dfs(int x,int flow){int res=flow;if(x==t) return flow;for(reg i=hd[x];i&&res;i=e[i].nxt){int y=e[i].to;if(d[y]==d[x]+1&&e[i].w){int k=dfs(y,min(res,e[i].w));if(!k) d[y]=0;res-=k;e[i].w-=k;e[i^1].w+=k;} }return flow-res; } bool bfs(){memset(d,0,sizeof d);l=1,r=0;q[++r]=s;d[s]=1;while(l<=r){int x=q[l++];for(reg i=hd[x];i;i=e[i].nxt){int y=e[i].to;if(e[i].w&&!d[y]){d[y]=d[x]+1;q[++r]=y;if(y==t) return true;}}}return false; } int num(int x,int y){return (x-1)*(h+1)+y+1; } int main(){rd(n);rd(h);rd(m);ans=n*h*h;s=0;t=num(n,h)+1;int tot=t;for(reg i=1;i<=n;++i){add(s,num(i,0),inf);for(reg j=0;j<h;++j){add(num(i,j),num(i,j+1),h*h-j*j);}}int l,r,x,c;for(reg i=1;i<=m;++i){rd(l);rd(r);rd(x);rd(c);if(x<h){++tot;add(tot,t,c);for(reg j=l;j<=r;++j){add(num(j,x+1),tot,inf);}}}int flow=0;while(bfs()){while(flow=dfs(s,inf)) ans-=flow;}ot(ans);return 0; }} signed main(){Miracle::main();return 0; }/*Author: *Miracle* */
转载于:https://www.cnblogs.com/Miracevin/p/10857458.html
CF1146G Zoning Restrictions相关推荐
- CF1146G Zoning Restrictions 最小割
CF1146G Zoning Restrictions 最小割 题意: 你准备在一条街上建房子.这条街上共有nn个地方可以用来建房子,每个房子高度最高为h.若你建了一个高度为aa的房子,那你将得到a^ ...
- cf----2019-08-14(The Doors,Zoning Restrictions Again,Detective Book)
总在不经意的年生,回首彼岸,纵然发现光景绵长. Three years have passes and nothing changed. It is still raining in London, ...
- Codeforces 1146G Zoning Restrictions dp
Zoning Restrictions 发现从左往右dp没有办法dp, 可以想到最大值的性质, 我们考虑构建笛卡尔树的过程. 如果 i 的l, r 的最大值, 那么经过 i 点的线段可以全部在枚举 i ...
- Forethought Future Cup - Elimination Round G. Zoning Restrictions 最大流(最小割)
题目链接: https://codeforces.com/contest/1146/problem/G 题意: 你现在要给 nnn 个位置制定高度 hi(1<=hi<=H)h_i (1&l ...
- Codeforces 1146G Zoning Restrictions
题目 https://codeforces.com/contest/1146/problem/G 题目翻译 你正在准备在一条路上建房子.这条路上有n个可以建房子的点,它们从左到右编号为1~n.你可以在 ...
- codeforces1146G Zoning Restrictions
题面 题意 在一条路上有标号为1-n的n座房子,每座房子最高为h,若一座房子的高度为x,则这座房子的收益为x*x,有m条限制,每条限制表示如果在l-r之间的所有房子的最大高度超过hi,则罚款ci.问所 ...
- 新浪微博授权失败:applications over the unaudited use restrictions
在用新浪微博授权第三方app时,授权失败,log显示 com.sina.weibo.sdk.exception.WeiboHttpException: {"error":" ...
- hibernate 高级查询 query 或查询 or ,Restrictions
hibernate 高级查询 query 或查询 or ,Restrictions 今天用了写hibernate高级查询时用了Restrictions(当然Expression也是可以以的)这个类.感 ...
- 如何在 SAP 电商云里设置 Time Restrictions
时间限制(Time Restrictions) 允许Commerce Cloud CMS 管理员指定何时向客户显示页面或组件.您只能向变体页面(variant pages)或组件(Components ...
最新文章
- android调试步骤,Android16_Android调试步骤
- 如何用Neo4j和Scikit-Learn做机器学习任务?| 附超详细分步教程
- 雷军在小米直面会丢的面子,在年度演讲都找回来了
- 2006_06_16_阿根廷的节日
- scala条件替换_scala - 有没有办法用scala中的高阶方法替换嵌套的For循环 - SO中文参考 - www.soinside.com...
- oracle生成42位,Oracle HowTo:如何确定Oracle是32 Bit(位)的还是64 Bit(位)的?
- kettle 的表输出 table output
- Bob‘s Problem
- java web 连接linux_如何将javaweb项目部署到linux下
- linux fall delay 10,Cell的Rise delay和Fall delay、Rise transition和fall transition
- python祝福祖国代码_C语言-笔记一
- 【转】如何读一篇论文
- java word模板 变量,Java-POI替换Word模板文档中的变量,生成Word文档
- 蒙版操作—剪切蒙版制作艺术字
- html页面出现504,web生产环境故障页面提示504错误
- eMule中的server无法连接问题
- 2020.7.6 -- Miller_Rabin和Pollard_Rho算法
- echarts实用篇(一)——饼状图
- android gif图片闪烁,Android中动态显示gif图片
- OpenCV-Python Feature2D 特征点检测(含SIFT/SURF/ORB/KAZE/FAST/BRISK/AKAZE)