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 ...
随机推荐
- htmlhomework2
<!DOCTYPE html> register register username: password: birth: gender: male female
- 阿里云区块链共创会:BaaS正式商业化 广邀合作伙伴共建生态
摘要: 阿里云宣布区块链服务Hyperledger Fabric版正式商业化,并发布生态合作伙伴计划. 2019年3月29日,阿里云区块链于深圳召开正式商业化共创会,宣布区块链服务Hyperledge ...
- LeedCode OJ --- Binary Tree Inorder Traversal
点击打开题目链接 今天只是写了递归的版本,因为还没想好怎么用迭代来实现,可以写的过程中,有一点是有疑问的,虽然我的代码可以AC. 问题是:主调函数是可以使用子函数中返回的在子函数中定义的vector. ...
- 通过iOS 9 SFSafariViewController提供完整的Web浏览体验
http://www.cocoachina.com/ios/20150826/13157.html 本文由CocoaChina译者@涛声依旧-忆往昔翻译自tutsplus校对:BenBeng原文:iO ...
- Java面向对象----接口概念
接口语法 interface 接口名{ //静态常量,抽象方法 } 特点 接口中只能存放静态常量和抽象方法 java接口是对功能的扩展 通过实现接口,java类可以实现多实现 一个类可以同时继承(ex ...
- Python基础:08列表解析与生成器表达式
一:列表解析 列表解析(List comprehensions)来自函数式编程语言Haskell .它可以用来动态地创建列表.它在 Python 2.0 中被加入. 列表解析的语法: [exp ...
- python的if循环和嵌套
1. if 条件: if语句块 执行流程:判断条件是否为真. 如果真. 执行if语句块 money = int(input('请输入你兜里的钱:')) if money >500 ...
- 你真的知道你看到的UTF-8字符是什么吗?
翻译自http://www.pixelstech.net/article/1397877200-You-know-what-UTF-8-is-when-you-see-it- Source : son ...
- Javascript 严格模式下不允许删除一个不允许删除的属性
如下代码,在严格模式下,如果删除 Object.prototype 浏览器会报错,目前 IE10 也支持 严格模式. <script> "use strict"; de ...
- Streamy 使用RDBMS