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 ...
随机推荐
- 【Leetcode 堆、快速选择、Top-K问题 BFPRT】数组中的第K个最大元素(215)
这道题很强大,引出了很多知识点 题目 在未排序的数组中找到第 k 个最大的元素.请注意,你需要找的是数组排序后的第 k 个最大的元素,而不是第 k 个不同的元素. 示例 1: 输入: [3,2,1,5 ...
- Jmeter VS LR参数取值方式和迭代方式
Jmeter的参数化 Jmeter中的参数就是变量. 变量的来源:测试计划.UDV.CSV.函数.正则表达式.数据库. 以Jmeter的CSV文件参数化为例:
- 纯CSS3绘制的黑色图标按钮组合
在线演示 本地下载
- CF789D Mike and distribution
题目连接 一道人类智慧题.... 这道题目可以转化为在a,b中的选出一些位置,使得这些位置处的值加起来大于没有选的位置的值 我们按照a的权值排序,选择第一个元素,其与元素两两分组,每组选择b更大的那一 ...
- 【记录Bug】 This is probably not a problem with npm. There is likely additional logging output above.
一个eslint的错误 我的报错如下 $ npm install > node-sass@4.11.0 install C:\Users\Administrator\Desktop\forGit ...
- JavaScript--模拟百度搜索下拉li
上效果: 主要思路: 函数indexOf() .join().innerHTML的使用,还有 用完的数组要清空 <!DOCTYPE html> <html> <head ...
- JavaScript--函数中()的作用
在函数中参数是函数的时候:function a(函数名) 与 function a(函数名()) 的区别: // 在函数里面() 是一个编组和立即执行的功能 /** * function autoPl ...
- OpenCV在各版本上的安装教程
目录 使用pip安装OpenCV 安装Python版的OpenCV 4 安装Python版的OpenCV 3 在OSX和 macOS上安装OpenCV 3 在Ubuntu上安装Python版的Open ...
- thinkphp5.0 composer安装phpmailer
1.安装:composer require phpmailer/phpmailer 2.引入:use PHPMailer\PHPMailer\PHPMailer: 3.调用:$mail = new P ...
- python print函数