AC日记——餐巾计划问题 洛谷 P1084
思路:
氧气优化水过;
代码:
#include <bits/stdc++.h>
using namespace std;
#define maxn 4005
#define maxque 1000005
#define INF 0x7fffffff
#define ll long long
ll n,head[maxn],E[maxque],V[maxque],W[maxque],F[maxque];
ll pi,qt,qc,st,sc,s,t,cnt=,day[maxn],pre[maxn],dis[maxn];
ll que[maxque],ans;
bool if_[maxn];
inline void in(ll &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'') Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
}
inline void edge_add(ll u,ll v,ll w,ll f)
{
E[++cnt]=head[u],V[cnt]=v,W[cnt]=w,F[cnt]=f,head[u]=cnt;
E[++cnt]=head[v],V[cnt]=u,W[cnt]=-w,F[cnt]=,head[v]=cnt;
}
bool spfa()
{
for(ll i=s;i<=t;i++)dis[i]=INF,if_[i]=false,pre[i]=-;
ll h=maxque>>,tail=h+,now;que[h]=s,if_[s]=true,dis[s]=;
while(h<tail)
{
now=que[h++],if_[now]=false;
for(ll i=head[now];i;i=E[i])
{
if(F[i]>&&W[i]+dis[now]<dis[V[i]])
{
pre[V[i]]=i,dis[V[i]]=dis[now]+W[i];
if(!if_[V[i]])
{
if(dis[V[i]]<=dis[que[h]]&&h<tail) que[--h]=V[i];
else que[tail++]=V[i];
if_[V[i]]=true;
}
}
}
}
return dis[t]!=INF;
}
int main()
{
in(n),s=,t=n*+;ll pos,now;
for(ll i=;i<=n;i++)in(day[i]);
in(pi),in(qt),in(qc),in(st),in(sc);
for(ll i=;i<=n;i++)
{
edge_add(s,i,pi,INF);
edge_add(i,t,,day[i]);
edge_add(s,i+n,,day[i]);
if(i+qt<=n) edge_add(i+n,i+qt,qc,INF);
if(i+st<=n) edge_add(i+n,i+st,sc,INF);
if(i!=n) edge_add(i+n,i+n+,,INF);
}
while(spfa())
{
now=t,pos=INF;
while(pre[now]!=-)
{
pos=min(pos,F[pre[now]]);
now=V[pre[now]^];
}
now=t,ans+=dis[t]*pos;
while(pre[now]!=-)
{
F[pre[now]]-=pos;
F[pre[now]^]+=pos;
now=V[pre[now]^];
}
}
printf("%lld\n",ans);
return ;
}
AC日记——餐巾计划问题 洛谷 P1084的更多相关文章
- AC日记——[SDOI2015]星际战争 洛谷 P3324
题目描述 3333年,在银河系的某星球上,X军团和Y军团正在激烈地作战. 在战斗的某一阶段,Y军团一共派遣了N个巨型机器人进攻X军团的阵地,其中第i个巨型机器人的装甲值为Ai.当一个巨型机器人的装甲值 ...
- AC日记——联合权值 洛谷 P1351
题目描述 无向连通图G 有n 个点,n - 1 条边.点从1 到n 依次编号,编号为 i 的点的权值为W i ,每条边的长度均为1 .图上两点( u , v ) 的距离定义为u 点到v 点的最短距离. ...
- AC日记——I Hate It 洛谷 P1531
题目背景 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少.这让很多学生很反感. 题目描述 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的 ...
- AC日记——神奇的幻方 洛谷 P2615(大模拟)
题目描述 幻方是一种很神奇的N*N矩阵:它由数字1,2,3,……,N*N构成,且每行.每列及两条对角线上的数字之和都相同. 当N为奇数时,我们可以通过以下方法构建一个幻方: 首先将1写在第一行的中间. ...
- AC日记——[CQOI2009]DANCE跳舞 洛谷 P3153
[CQOI2009]DANCE跳舞 思路: 二分+最大流: 代码: #include <cstdio> #include <cstring> #include <iost ...
- AC日记——松江1843路 洛谷七月月赛
松江1843路 思路: 三分: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 #define ...
- AC日记——严酷的训练 洛谷 P2430
严酷的训练 思路: 背包: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 5005 int n,m,bi[m ...
- AC日记——[SDOI2010]大陆争霸 洛谷 P3690
[SDOI2010]大陆争霸 思路: dijkstra模板: 代码: #include <bits/stdc++.h> using namespace std; #define maxn ...
- AC日记——小魔女帕琪 洛谷 P3802
小魔女帕琪 思路: 概率公式计算: 代码: #include <bits/stdc++.h> using namespace std; ],sig; int main() { ;i< ...
随机推荐
- UVA10766:Organising the Organisation(生成树计数)
Organising the Organisation 题目链接:https://vjudge.net/problem/UVA-10766 Description: I am the chief of ...
- c# MD5盐值加密
using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptograph ...
- [LeetCode] 4. Median of Two Sorted Arrays ☆☆☆☆☆
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two ...
- linux用户管理和文件权限
linux用户管理和文件权限 新建用户:useradd ftpuser useradd -g gxx userxx修改密码:passwd ftpuser新增用户组:# groupadd gr ...
- 消除float浮动的影响
一. 在父元素中当前浮动元素下面添加一个空的div 添加clear属性 <div style="displya:none;clear: left;"></div& ...
- 【NOIP】提高组2012 vigenere密码
[算法]模拟 #include<cstdio> #include<cstring> ; char sm[maxm],key[maxm],s[maxm]; int len,len ...
- 【BZOJ】3566: [SHOI2014]概率充电器
[算法]树型DP+期望DP [题意]一棵树上每个点均有直接充电概率qi%,每条边有导电概率pi%,问期望有多少结点处于充电状态? [题解]引用自:[BZOJ3566][SHOI2014]概率充电器 树 ...
- Zen Cart、Joy-Cart、Magento、ShopEX、ECshop电子商务系统比较
1.Zen Cart 优点:历史较久,系统经过长时间充分的测试,比较成熟:免费开源便于功能二次开发:基础功能强大:安装插件简单,修改文件很少,甚至不用修改文件:应用非常广泛,插件.模块更新快,其中多为 ...
- VMware 12安装虚拟机Mac OS X 10.10不能上网问题
1:从本机中选择打开连接网络,选择本地连接.如果是无线网可以选择无线网. 1: 2: 控制面板--->网络和共享中心 2:选择属性,点击共享按钮. 3:将internet连接共享下面选项都选中 ...
- elementui table 多选 获取id
//多选相关方法 toggleSelection(rows) { if (rows) { rows.forEach(row => { this.$refs.multipleTable.toggl ...