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=;bool fl=false;
while(!isdigit(ch=getchar()))(ch=='-')&&(fl=true);
for(x=numb;isdigit(ch=getchar());x=x*+numb);
(fl==true)&&(x=-x);
}
template<class T>il void output(T x){if(x/)output(x/);putchar(x%+'');}
template<class T>il void ot(T x){if(x<) 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=;
const int P=N*N;
const int inf=0x3f3f3f3f;
int n,m,h;
int s,t;
struct node{
int nxt,to;
int w;
}e[*(P+P+N*N)];
int hd[P],cnt=;
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=;
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]+&&e[i].w){
int k=dfs(y,min(res,e[i].w));
if(!k) d[y]=;
res-=k;
e[i].w-=k;
e[i^].w+=k;
}
}
return flow-res;
}
bool bfs(){
memset(d,,sizeof d);
l=,r=;
q[++r]=s;
d[s]=;
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]+;
q[++r]=y;
if(y==t) return true;
}
}
}
return false;
}
int num(int x,int y){
return (x-)*(h+)+y+;
}
int main(){
rd(n);rd(h);rd(m);
ans=n*h*h;
s=;t=num(n,h)+;
int tot=t;
for(reg i=;i<=n;++i){
add(s,num(i,),inf);
for(reg j=;j<h;++j){
add(num(i,j),num(i,j+),h*h-j*j);
}
}
int l,r,x,c;
for(reg i=;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+),tot,inf);
}
}
}
int flow=;
while(bfs()){
while(flow=dfs(s,inf)) ans-=flow;
}
ot(ans);
return ;
} }
signed main(){
Miracle::main();
return ;
} /*
Author: *Miracle*
*/

CF1146G Zoning Restrictions的更多相关文章

  1. codeforces A. Zoning Restrictions Again

    A. Zoning Restrictions Again ou are planning to build housing on a street. There are n spots availab ...

  2. Codeforces1146G. Zoning Restrictions

    Description You are planning to build housing on a street. There are n spots available on the street ...

  3. CF集萃2

    CF1155D - Beautiful Array 题意:给你一个序列和x,你可以选择任意一个子串(可以为空)乘上x,使得得到的序列最大子串和最大.求这个最大值.30w,2s. 解:设fi,0/1/2 ...

  4. 【CF1146】Forethought Future Cup - Elimination Round

    Forethought Future Cup - Elimination Round 窝也不知道这是个啥比赛QwQ A. Love "A" 给你一个串,你可以删去若干个元素,使得最 ...

  5. Hibernate的 Restrictions用法

    方法说明 方法 说明 Restrictions.eq = Restrictions.allEq 利用Map来进行多个等于的限制 Restrictions.gt > Restrictions.ge ...

  6. 【WebGoat习题解析】Parameter Tampering->Bypass HTML Field Restrictions

    The form below uses HTML form field restrictions. In order to pass this lesson, submit the form with ...

  7. 新浪微博授权失败:applications over the unaudited use restrictions

    在用新浪微博授权第三方app时,授权失败,log显示 com.sina.weibo.sdk.exception.WeiboHttpException: {,"request":&q ...

  8. Hibernate Criteria Restrictions

    HQL运算符 QBC运算符 含义 = Restrictions.eq() 等于equal <>  Restrictions.ne() 不等于not equal >  Restrict ...

  9. hibernate criteria中Restrictions的用法

    方法说明 方法 说明 Restrictions.eq = Restrictions.allEq 利用Map来进行多个等于的限制 Restrictions.gt > Restrictions.ge ...

随机推荐

  1. poj2195&&hdu1533 最小费用流

    这题也可以用km做,我写的代码km比费用流快很多. 最小费用流: #include<stdio.h> #include<string.h> #include<math.h ...

  2. swift 风骚的Guard语法

    http://blog.csdn.net/pjk1129/article/details/48627153#0-qzone-1-64255-d020d2d2a4e8d1a374a433f596ad14 ...

  3. Facebook POP动效库使用教程

    编者注:用Origami作iOS动效的同学如果愁怎么实现,可以把这个给开发看看作为参考哦 如果说Origami这款动效原型工具是Facebook Paper的幕后功臣,那么POP便是Origami的地 ...

  4. 2019-8-31-C#-循环的判断会进来几次

    title author date CreateTime categories C# 循环的判断会进来几次 lindexi 2019-08-31 16:55:58 +0800 2018-06-14 0 ...

  5. POJ 1679The Unique MST

    Description Given a connected undirected graph, tell if its minimum spanning tree is unique. Definit ...

  6. 中国境内PE\VC\投资公司名单

    中国境内PE\VC\投资公司名单 1.青云创投 2.高盛 3.红杉资本 4.鼎晖创投 5.枫丹国际 6.派杰投资银行 7.凯雷投资 8.长安私人资本 9.格林雷斯 10.汉能资本 11.启明创投 12 ...

  7. 【JZOJ4845】【NOIP2016提高A组集训第5场11.2】寻找

    题目描述 "我有个愿望,我希望穿越一切找到你." 这是个二维平面世界,平面上有n个特殊的果实,我从(0,0)点出发,希望得到尽量多的果实,但是出于某种特殊的原因,我的运动方式只有三 ...

  8. iOS开发周报-- 第一期

    从Java转iOS第一个项目总结 http://www.cocoachina.com/ios/20150417/11595.html icon设计探讨:图标,文字,还是图标加文字? http://ww ...

  9. phpcms分类信息地区识别跳转

    <script src="http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js"></scri ...

  10. SDUT-2139_从起始点到目标点的最短步数(BFS)

    数据结构实验之图论五:从起始点到目标点的最短步数(BFS) Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 在古老的魔兽 ...