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的更多相关文章
- codeforces A. Zoning Restrictions Again
A. Zoning Restrictions Again ou are planning to build housing on a street. There are n spots availab ...
- Codeforces1146G. Zoning Restrictions
Description You are planning to build housing on a street. There are n spots available on the street ...
- CF集萃2
CF1155D - Beautiful Array 题意:给你一个序列和x,你可以选择任意一个子串(可以为空)乘上x,使得得到的序列最大子串和最大.求这个最大值.30w,2s. 解:设fi,0/1/2 ...
- 【CF1146】Forethought Future Cup - Elimination Round
Forethought Future Cup - Elimination Round 窝也不知道这是个啥比赛QwQ A. Love "A" 给你一个串,你可以删去若干个元素,使得最 ...
- Hibernate的 Restrictions用法
方法说明 方法 说明 Restrictions.eq = Restrictions.allEq 利用Map来进行多个等于的限制 Restrictions.gt > Restrictions.ge ...
- 【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 ...
- 新浪微博授权失败:applications over the unaudited use restrictions
在用新浪微博授权第三方app时,授权失败,log显示 com.sina.weibo.sdk.exception.WeiboHttpException: {,"request":&q ...
- Hibernate Criteria Restrictions
HQL运算符 QBC运算符 含义 = Restrictions.eq() 等于equal <> Restrictions.ne() 不等于not equal > Restrict ...
- hibernate criteria中Restrictions的用法
方法说明 方法 说明 Restrictions.eq = Restrictions.allEq 利用Map来进行多个等于的限制 Restrictions.gt > Restrictions.ge ...
随机推荐
- DELL(linux 系统里系统掉盘)(阵列Foreign)命令行里重做阵列
故障现象 (阵列Foreign 系统下重做阵列) 例:四合一机器(DELL_XENCOMPA09) 有四个硬盘 如图 少认到一个 df -h fdisk -l 2>/dev/null | gr ...
- 利用幂等性区分HTTP的POST与PUT请求
1.什么是幂等性 幂等性概念:幂等通俗来说是指不管进行多少次重复操作,都是实现相同的结果. 2.REST请求中哪些是幂等操作 GET,PUT,DELETE都是幂等操作,而POST不是,以下进行分析: ...
- javascript正则表达式和字符串RegExp
这篇文章主要介绍了javascript正则表达式和字符串RegExp and String(一)的相关资料,需要的朋友可以参考下 前言 正则表达式是javascript非常重要和常用的 ...
- TCPThree_C杯 Day2
T1 我已经被拉格朗日插值蒙蔽了双眼,变得智障无比. 第一反应就是拉格朗日插值,然后就先放下了它. 模数那么小,指数那么大,这是一套noip模拟题,拉格朗日,你脑袋秀逗了? 无脑暴力20分贼开心. 正 ...
- zabbix源码编译安装以及添加第一台host监控
基础准备 硬件需求 数据库需求 软件需求 其他软件需求 安装 安装方式 source code 编译好的二进制包 rpm或者deb 源码编译安装部署zabbix以及附件 前提准备 最小化安装操作系 ...
- ios开发――解决UICollectionView的cell间距与设置不符问题
在用UICollectionView展示数据时,有时我们希望将cell的间距调成一个我们想要的值,然后查API可以看到有这么一个属性: - (CGFloat)minimumInteritemSpaci ...
- POJ-2502_Subway
Subway Time Limit: 1000MS Memory Limit: 65536K Description You have just moved from a quiet Waterloo ...
- zip解决杨辉三角问题
杨辉三角原型: / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ 实现: a = [1] while True: print(a) ...
- 最强 NLP 预训练模型库 PyTorch-Transformers 正式开源:支持 6 个预训练框架,27 个预训练模型
先上开源地址: https://github.com/huggingface/pytorch-transformers#quick-tour 官网: https://huggingface.co/py ...
- hdu 3374 String Problem (字符串最小最大表示 + KMP求循环节)
Problem - 3374 KMP求循环节. http://www.cnblogs.com/wuyiqi/archive/2012/01/06/2314078.html 循环节推导的证明相当 ...