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 ...
随机推荐
- circos pipeline
# /usr/bin/env python# coding=utf-8#################################### Author : yunkeli# Version : ...
- web渗透测试之sqlmap拿到数据库信息
通过扫描我们发现目标网站存在sql注入漏洞,我们访问该里面后发现该网站里面有个表格提交参数.确实存在没有过滤 使用sqlmap扫描发现漏洞的确存在,这里是布尔盲注 查看当前数据库名 查看表名得到以下信 ...
- 【译】Database Profiling with Visual Studio
你是否在排查运行缓慢的 web 应用程序时怀疑是数据库层造成的?以前排查数据库层需要特定的工具,现在可以使用 Visual Studio 的 Performance Explorer 中的数据库分析工 ...
- 牛客网PAT练兵场-程序运行时间
题解:无(注意下四舍五入和输出格式即可) 题目地址:https://www.nowcoder.com/questionTerminal/fabbb85fc2d342418bcacdf0148b6130 ...
- C++奇淫技巧
一.关于:的妙用 如下代码 #include<cstdio> #include<iostream> typedef struct point{ int a; int b; po ...
- 新手学习java路线
关于新手学习java的路线 笔者也是根据这个路线学习的,希望对你们有所帮助. 首先你要确定你是学习java 并且能够踏踏实实的走下去.一定要多学习,我也可以一直陪你走下去的. 笔者一年工作经验,科班毕 ...
- 《HelloGitHub》第 53 期
兴趣是最好的老师,HelloGitHub 就是帮你找到兴趣! 简介 分享 GitHub 上有趣.入门级的开源项目. 这是一个面向编程新手.热爱编程.对开源社区感兴趣 人群的月刊,月刊的内容包括:各种编 ...
- python+requests+unittest执行自动化接口测试
1.安装requests.xlrd.json.unittest库 <1>pip 命令安装: pip install requestspip install xlrdpip install ...
- 力扣Leetcode 1518. 换酒问题
小区便利店正在促销,用 numExchange 个空酒瓶可以兑换一瓶新酒.你购入了 numBottles 瓶酒. 如果喝掉了酒瓶中的酒,那么酒瓶就会变成空的. 请你计算 最多 能喝到多少瓶酒. 示例: ...
- js获取N天后的日期
这个javascript函数是获取当前时间前后N天日期的方法,可以得到昨天,今天,明天,一月前,三月前,半年前,一年前的日期,只要修改参数就可以实现得到任何一个天数.具体用法如下: function ...