CodeForces - 434D Nanami's Power Plant
题目大意:
给定一个长为n的序列,序列中的第i为上的值\(x_i\),序列第i位上的值\(x_i\in[l_i,r_i]\),价值为\(f_i(x_i)\),其中\(f_i(x) = a_ix^2 + b_ix + c_i\),同时给出m个限制条件,每个限制条件用一个三元组\(<u,v,d>\)来表示,需要序列满足\(x_u \leq x_v + d\)。求在满足所限制条件的情况下的\(f_i(x_i)\)的最大和。
其中满足(\(1 \leq n \leq 50, 0 \leq m \leq 100 , -100 \leq l_i \leq r_i \leq 100)\)
题目解答:
这道题跟[bzoj 3144 切糕]类似,由于网上关于切糕的题解已经烂大街了,在这里就不说了.
首先我们考虑在没有\(x_i\)的限制之下的答案计算:
直接取每段内的\(max\)不就好了嘛... ...
开一开脑洞,你就会构造出一个跟切糕差不多的层次模型
这不过这次是"最大割"而已
我们可以把所有有价值的边权全部都被所有值中的最大值减一下
这样我们直接求最小流再调整就行了。
而对于\(X_u <= X_v + d\)的限制
我们直接应用和切糕一样的思想来限制就可以了
一遍最大流即可
\(ans = (max(f_i(x)) + 1)*n - maxflow\)
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
x=0;char ch;bool flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
inline int cat_max(const int &a,const int &b){return a>b ? a:b;}
inline int cat_min(const int &a,const int &b){return a<b ? a:b;}
const int maxn = 51;
const int maxm = 128;
const int maxnode = 25400;
const int maxedge = 254000;
const int inf = 0x3f3f3f3f;
struct Edge{
int to,next,cap;
}G[maxedge];
int head[maxnode],cnt=1;
void add(int u,int v,int c){
G[++cnt].to = v;
G[cnt].next = head[u];
G[cnt].cap = c;
head[u] = cnt;
}
inline void insert(int u,int v,int c){
add(u,v,c);add(v,u,0);
}
int dis[maxnode],q[maxnode],l,r;
int S,T;
#define v G[i].to
bool bfs(){
memset(dis,-1,sizeof dis);
dis[S] = 0;l = 0;r = -1;
q[++r] = S;
while(l <= r){
int u = q[l++];
for(int i = head[u];i;i=G[i].next){
if(dis[v] == -1 && G[i].cap){
dis[v] = dis[u] + 1;
q[++r] = v;
}
}
}return dis[T] != -1;
}int cur[maxnode];
int dfs(int u,int f){
if(u == T || f == 0) return f;
int ret = 0;
for(int &i = cur[u];i;i=G[i].next){
if(dis[v] == dis[u] + 1 && G[i].cap){
int x = dfs(v,cat_min(G[i].cap,f));
ret += x;f -= x;
G[i].cap -= x;G[i^1].cap += x;
if(f == 0) break;
}
}if(ret == 0) dis[u] = -1;
return ret;
}
inline int dinic(){
int ret = 0;
while(bfs()){
memcpy(cur,head,sizeof head);
ret += dfs(S,inf);
}return ret;
}
#undef v
int n;
inline int f(int x,int y){
y += 102;
return x*210+y;
}
int a[maxn],b[maxn],c[maxn],le[maxn],ri[maxn];
inline int calc(int i,int x){
return a[i]*x*x+b[i]*x+c[i];
}
int main(){
S = maxnode - 5;T = S+1;
read(n);int m;read(m);
int lim = -inf;
for(int i=1;i<=n;++i){
read(a[i]);read(b[i]);read(c[i]);
}
for(int i=1;i<=n;++i){
read(le[i]);read(ri[i]);
insert(S,f(i,le[i]-1),inf);
for(int j=le[i];j<=ri[i];++j){
lim = cat_max(lim,calc(i,j)+1);
}
insert(f(i,ri[i]),T,inf);
}
for(int i=1;i<=n;++i){
for(int j=le[i];j<=ri[i];++j){
insert(f(i,j-1),f(i,j),lim - calc(i,j));
}
}
for(int i=1,u,v,d;i<=m;++i){
read(u);read(v);read(d);
for(int j=le[u];j<=ri[u];++j){
if(j - d - 1 >= le[v] - 1 && j - d -1 <= ri[v])
insert(f(u,j-1),f(v,j-d-1),inf);
}
}
int ans = dinic();
printf("%d\n",lim*n - ans);
getchar();getchar();
return 0;
}
CodeForces - 434D Nanami's Power Plant的更多相关文章
- Codeforces Round #248 (Div. 1) D - Nanami's Power Plant 最小割
D - Nanami's Power Plant 思路:类似与bzoj切糕那道题的模型.. #include<bits/stdc++.h> #define LL long long #de ...
- 【CF434D】Nanami's Power Plant 最小割
[CF434D]Nanami's Power Plant 题意:有n个二次函数$y=a_ix^2+b_ix+c_i$($a_i,b_i,c_i$是整数),第i个函数要求x的取值在$[l_i,r_i]$ ...
- CF434D Nanami's Power Plant 最小割
传送门 因为连距离限制的边的细节调了贼久QAQ 这个题和HNOI2013 切糕性质相同,都是有距离限制的最小割问题 对于每一个函数,用一条链记录变量\(x\)在不同取值下这个函数的贡献.对于一个\(x ...
- CF434D Nanami's Power Plant
就是切糕那道题,首先对每个函数连一串,然后\(x_u\leq x_v+d\)这个条件就是\(u\)函数\(i\)取值连向\(v\)函数\(i-d\)取值边权为inf,然后答案就是最小割了. #incl ...
- 缩点:Power Plant;
题目传送门:[UVALive 6437]Power Plant 题目大意:T组数据,给定一幅带权图(n, m), 然后给定k个点, 与图中存在有若干条边.每个点都要至少要和这k个点的一个点直接或间接相 ...
- Nuclear Power Plant ZOJ - 3840 树形dp
There are N (1 ≤ N ≤ 105) cities on land, and there are N - 1 wires connecting the cities. Therefore ...
- [Codeforces 1245D] Shichikuji and Power Grid (最小生成树)
[Codeforces 1245D] Shichikuji and Power Grid (最小生成树) 题面 有n个城市,坐标为\((x_i,y_i)\),还有两个系数\(c_i,k_i\).在每个 ...
- 【CodeForces】906 D. Power Tower 扩展欧拉定理
[题目]D. Power Tower [题意]给定长度为n的正整数序列和模数m,q次询问区间[l,r]累乘幂%m的答案.n,q<=10^5,m,ai<=10^9. [算法]扩展欧拉定理 [ ...
- UVA Live 6437 Power Plant 最小生成树
题意: 有许多油井和村庄什么的,让你使得这些村庄能连通一个油井就好了.第一行给你一个数字T代表有T组测试数据,第二行有 M , N , K ,M代表包括油井在内的村庄数,N 代表有N个 两两连通的地方 ...
随机推荐
- MVC中的ViewData、ViewBag和TempData
一.ViewBag和ViewData的定义 public dynamic ViewBag { get; } public ViewDataDictionary ViewData { get; set; ...
- leetCode 84.Largest Rectangle in Histogram (最大矩形直方图) 解题思路和方法
Given n non-negative integers representing the histogram's bar height where the width of each bar is ...
- leetCode 47.Permutations II (排列组合II) 解题思路和方法
Permutations II Given a collection of numbers that might contain duplicates, return all possible un ...
- python学习(七)字典学习
#!/usr/bin/python # 字典 # 当时学java的时候, 语言基础就学了好久, 然后是各种API, 最后才是集合 # 键值对, 可变 # 1. 映射操作 D = {'food' : ' ...
- XMLHttpRequest cannot load ''. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' ' is therefore not allowed access.
ajax跨域 禁止访问! 利用Access-Control-Allow-Origin响应头解决跨域请求
- mongodb的mongod.lock文件及oplog文件
在mongodb的启动时,在数据目录下,会生成一个mongod.lock文件.如果在正常退出时,会清除这个mongod.lock文件,若要是异常退出,在下次启动的时候,会禁止启动,从而保留一份干净的一 ...
- 远程服务器上的weblogic项目管理(二)发布完成后如何重启weblogic容器
前面说到了每次更新服务器项目的java文件与配置文件后,需要更新weblogic容器以完成更新加载,下面来说说如何更新weblogic容器: 第一种方法可以通过ssh shell client工具直接 ...
- Pentaho BIServer Community Edtion 6.1 使用教程 第二篇 迁移元数据 [HSQLDB TO MySQL]
第一部分 迁移原因 Pentaho BI 社区版服务的很多元数据信息存储在数据库汇总,其默认使用HSQLDB 数据库,即借助它存储自身的资料库,比如 Quartz 调度信息.业务资料库连接信息(数据 ...
- Oracle伪列rownum
Oracle基础知识:伪列rownum,伪列就像表中的列一样,但是在表中并不存储.伪列只能查询,不能进行增删改操作. 在查询的结果集中,ROWNUM为结果集中每一行标识一个行号,第一行返回1,第二行返 ...
- PAT 乙级 1081. 检查密码 (15) 【字符串】
题目链接 https://www.patest.cn/contests/pat-b-practise/1081 思路 有一个坑点 可能会输入空格 也就是说 要用 geline 或者 gets() 然后 ...