Codeforces1146G. Zoning Restrictions
Description
You are planning to build housing on a street. There are n spots available on the street on which you can build a house. The spots are labeled from 1 to n from left to right. In each spot, you can build a house with an integer height between 0 and h.
In each spot, if a house has height a, you can gain a2 dollars from it.
The city has m zoning restrictions though. The i-th restriction says that if the tallest house from spots li to ri is strictly more than xi, you must pay a fine of ci.
You would like to build houses to maximize your profit (sum of dollars gained minus fines). Determine the maximum profit possible.
Input
The first line contains three integers n,h,m (1≤n,h,m≤50) — the number of spots, the maximum height, and the number of restrictions, respectively.
Each of the next m lines contains four integers li,ri,xi,ci (1≤li≤ri≤n, 0≤xi≤h, 1≤ci≤5000).
Output
Print a single integer denoting the maximum profit you can make.
Solution
大意就是建房子,房子最大高度为h,对于高度为i的建筑,收益为i*i。现在有m个限制,对于第i个限制,在li~ri这段区间内,高度如果有超过xi的需要罚款ci元。问最大收益
考虑最小割来求损失
首先设一个超级源S和超级汇T
将每一个点拆成0~h-1即h个点
将0点与S连一条正无穷的边
随后对于这h个点:
- 第i个点与第i+1个点之间连一条hh-ii的边,表示损失
割掉第i个点与第i+1个点之间的连边就代表选了第i个点
随后,对于每个限制
- li~ri区间内的第xi个点与该点连一条正无穷的边,因为这条边不可能被割
该点再与T连一条ci的边,表示损失
最后输出即可
(第一次打sap,之前都在打dinic呢)
#include <cstdio>
#include <algorithm>
#define inf 1000000007
#define S 4000
#define T 4001
#define M 20001
#define N 5001
#define open(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
#define id(x,y) (x-1)*(h+1)+y+1
using namespace std;
int len,n,h,m,l,r,x,c,cnt,ans,i,j,go[M],to[M],last[N],w[M],dis[N],gap[N];
void make(int x,int y,int z)
{
go[++len]=y;to[len]=last[x];w[len]=z;last[x]=len;
}
void add(int x,int y,int z)
{
make(x,y,z);
make(y,x,0);
}
int sap(int x,int flow)
{
if (x==T) return flow;
int tmp,have=flow;
for (int i=last[x];i;i=to[i])
{
if (w[i] && dis[x]==dis[go[i]]+1)
{
tmp=sap(go[i],min(have,w[i]));
w[i]-=tmp;w[i^1]+=tmp;have-=tmp;
if (!have) return flow;
}
}
if (!--gap[dis[x]]) dis[S]=T;
++gap[++dis[x]];
return flow-have;
}
int main()
{
open("restrictions");
scanf("%d%d%d",&n,&h,&m);
len=1;
for (i=1;i<=n;i++)
{
add(S,id(i,0),inf);
for (j=0;j<h;j++)
{
add(id(i,j),id(i,j+1),h*h-j*j);
}
}
cnt=id(n,h);
for (i=1;i<=m;i++)
{
scanf("%d%d%d%d",&l,&r,&x,&c);
if (x==h) continue;
add(++cnt,T,c);
for (j=l;j<=r;j++)
add(id(j,x+1),cnt,inf);
}
ans=n*h*h;
while (dis[S]<T)
ans-=sap(S,inf);
printf("%d",ans);
return 0;
}
Codeforces1146G. Zoning Restrictions的更多相关文章
- CF1146G Zoning Restrictions
CF1146G Zoning Restrictions 网络流 h<=50? 直接都选择最大的,ans=n*h*h 最小割 考虑舍弃或者罚款 有一个>x就要罚款? 经典取值限制的模型:切糕 ...
- codeforces A. Zoning Restrictions Again
A. Zoning Restrictions Again ou are planning to build housing on a street. There are n spots availab ...
- 【CF1146】Forethought Future Cup - Elimination Round
Forethought Future Cup - Elimination Round 窝也不知道这是个啥比赛QwQ A. Love "A" 给你一个串,你可以删去若干个元素,使得最 ...
- CF集萃2
CF1155D - Beautiful Array 题意:给你一个序列和x,你可以选择任意一个子串(可以为空)乘上x,使得得到的序列最大子串和最大.求这个最大值.30w,2s. 解:设fi,0/1/2 ...
- 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 ...
随机推荐
- CentOS 6.x/7.x上安装git
yum安装 # yum info git # yum install -y git 可以通过下面的命令来检查是否安装了git环境 git --version 参考:如何在CentOS 6.x/7.x上 ...
- Mybatis动态语句
If元素If元素是简单的条件判断逻辑,满足制定条件时追加if元素的SQL,不满足条件时不追加,使用格式如下: <select ….> SQL语句1 <if test=“条件表达式”& ...
- 数据中台实战(一):以B2B电商亿订为例,谈谈产品经理视角下的数据埋点
本文以B2B电商产品“亿订”为实例,与大家一同谈谈数据中台的数据埋点. 笔者所在公司为富力环球商品贸易港,是富力集团旗下汇聚原创设计师品牌及时尚买手/采购商两大社群,通过亿订B2B电商.RFSHOWR ...
- 科普,想成为厉害的 Java 后端程序员,你需要懂这 13 个知识点
老读者就请肆无忌惮地点赞吧,微信搜索[沉默王二]关注这个在九朝古都洛阳苟且偷生的程序员.本文 GitHub github.com/itwanger 已收录,里面还有我精心为你准备的一线大厂面试题. 站 ...
- ZERO:新手应该如何学习SEO优化
http://www.wocaoseo.com/thread-325-1-1.html 有一个10000小时理论,说是在各行各业,想成为大师级的人物就要付出10000小时的努力,在SEO这边也是如此. ...
- python习题 随机密码生成 + 连续质数计算
随机密码生成 描述 补充编程模板中代码,完成如下功能: ...
- Python数据清洗:提取爬虫文本中的电话号码
步骤索引 效果展示 注意事项 代码 很多人学习python,不知道从何学起.很多人学习python,掌握了基本语法过后,不知道在哪里寻找案例上手.很多已经做案例的人,却不知道如何去学习更加高深的知识. ...
- Azure Storage 系列(二) .NET Core Web 项目中操作 Blob 存储
一,引言 上一篇文章,我们介绍到在实际项目中系统会产生大量的日志文件,用户上传的头像等等,同时也介绍到可以使用Azure Blob Storage 来存储项目中的一些日志文件,用户头像,用户视频等等. ...
- MyBatis-Plus分页——PageHelper和IPage介绍
两个都用于分页,常用的应该是PageHelper了,理解了一下源码后发现IPage比PageHelper好用. 使用方法是 PageHelper.startPage()然后后边写sql就可以. 紧接着 ...
- Oracle12C创建视图权限不足
授权: GRANT CREATE VIEW TO c##scott; 作者:彼岸舞 时间:2020\06\23 内容关于:Oracle 本文属于作者原创,未经允许,禁止转发