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 ...
随机推荐
- php实现视频拍照上传头像功能实例代码
如果要在php中实现视频拍照我们需要借助于flash插件了,由flash拍出的确照片我们再通过php的$GLOBALS ['HTTP_RAW_POST_DATA']接受数据,然后保存成图片就可以了,下 ...
- GPU虚拟机创建时间深度优化
桔妹导读:GPU虚拟机实例创建速度慢是公有云面临的普遍问题,由于通常情况下创建虚拟机属于低频操作而未引起业界的重视,实际生产中还是存在对GPU实例创建时间有苛刻要求的业务场景.本文将介绍滴滴云在解决 ...
- Mybatis Log plugin 破解!!!
前言 今天重新装了IDEA2020,顺带重装了一些插件,毕竟这些插件都是习惯一直在用,其中一款就是Mybatis Log plugin,按照往常的思路,在IDEA插件市场搜索安装,艹,眼睛一瞟,竟然收 ...
- HttpServletRespnse 对象 相关基本应用
HttpServletRespnse 对象相关基本应用 向浏览器输出数据 getOutputStream() @Override protected void service(HttpServletR ...
- Python3网络爬虫之requests动态爬虫:拉钩网
操作环境: Windows10.Python3.6.Pycharm.谷歌浏览器目标网址: https://www.lagou.com/jobs/list_Python/p-city_0?px=defa ...
- Python post请求模拟登录淘宝并爬取商品列表
一.前言 大概是一个月前就开始做淘宝的爬虫了,从最开始的用selenium用户配置到selenium模拟登录,再到这次的post请求模拟登录.一共是三篇博客,记录了我爬取淘宝网的经历.期间也有朋友向我 ...
- 【HttpRunner v3.x】笔记 ——2. 用脚手架快速创建项目
环境装好了,相信很多童鞋已经迫不及待的想run起来了,但是面对一个陌生的框架又无从下手.没关系,我们可以用脚手架来快速生成一个httprunner项目. 一.快速生成项目 我们不妨先输入httprun ...
- AcWing 285. 没有上司的舞会(树形dp入门)
Ural大学有N名职员,编号为1~N. 他们的关系就像一棵以校长为根的树,父节点就是子节点的直接上司. 每个职员有一个快乐指数,用整数 HiHi 给出,其中 1≤i≤N1≤i≤N. 现在要召开一场周年 ...
- SpringBoot系列之从入门到精通系列教程
对应SpringBoot系列博客专栏,例子代码,本博客不定时更新 Spring框架:作为JavaEE框架领域的一款重要的开源框架,在企业应用开发中有着很重要的作用,同时Spring框架及其子框架很多, ...
- H5选择器
1.标签选择器 注意点:1. 标签选择器选中当前所有的标签,而不能单独选择某个标签 2.标签选择器不无多深都能被选中 3.只要是HTML中的标签就可以作为表亲啊选择器(h/a/img/ul/o ...