【BZOJ 1221】 [HNOI2001] 软件开发
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
```cpp
/*
设一个超级源点S和超级汇点T
S和2*i-1各连一条容量为ni的边。
花费为0
表示每天都会产生ni条要洗的毛巾
S和2*i各连一条容量为INF的边
花费为f
表示新买毛巾用
2*i-1和2*(i+a)连容量为INF的边
花费为fa
2*i-1和2*(i+b)连容量为INF的边
花费为fb
表示用完的毛巾消毒。
当然。用完的毛巾还能不马上消毒。
所以
2*i-1和2*(i+1)-1连容量为INF的边。花费为0
然后对于2*i,每个点都和汇点T连容量为ni的边。
表示每天要用的毛巾个数。
这样满流的时候就是符合要求的了。
跑个费用流就可以了。
*/
**边数一定要谨慎算。。**
</font>
<font color = black size = 6> 【代码】</font>
```cpp
#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define ms(x,y) memset(x,y,sizeof x)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
using namespace std;
const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};
const int N = 2e3;
const int M = 2e4;
const int INF = 0x3f3f3f3f;
struct abc{
int from,en,flow,nex,cost;
};
int n,A,B,F,FA,FB,fir[N+100],dis[N+100],pre[N+100],mi[N+100],totm,a[N+100],ans;
bool inq[N+10];
queue<int> dl;
abc bian[M];
void add(int x,int y,int flow,int cost){
bian[totm].nex = fir[x];
fir[x] = totm;
bian[totm].from = x;
bian[totm].en = y;
bian[totm].cost = cost;
bian[totm].flow = flow;
totm++;
bian[totm].nex = fir[y];
fir[y] = totm;
bian[totm].from = y;
bian[totm].en = x;
bian[totm].cost = -cost;
bian[totm].flow = 0;
totm++;
}
bool spfa(int s,int t){
ms(dis,INF),ms(inq,0),ms(mi,INF);
dis[s] = 0,inq[s] = 1;
dl.push(s);
pre[t] = -1;
while (!dl.empty()){
int x = dl.front();
inq[x] = false;
dl.pop();
for (int i = fir[x];i!=-1;i = bian[i].nex){
int y = bian[i].en;
if (bian[i].flow && dis[y] > dis[x] + bian[i].cost){
dis[y] = dis[x] + bian[i].cost;
mi[y] = min(bian[i].flow,mi[x]);
pre[y] = i;
if (!inq[y]){
inq[y] = true;
dl.push(y);
}
}
}
}
if (pre[t]==-1) return false;
int now = t;
while (now != s){
int temp = pre[now];
bian[temp].flow -= mi[t];
bian[temp^1].flow += mi[t];
now = bian[temp].from;
ans += mi[t]*bian[temp].cost;
}
return true;
}
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
ms(fir,255);
cin >> n >> A >> B >> F >> FA >> FB;
for (int i = 1;i <= n;i++) cin >> a[i];
for (int i = 1;i <= n;i++) {
add(0,2*i-1,a[i],0);
add(0,2*i,INF,F);
if (i<n) add(2*i-1,2*(i+1)-1,INF,0);
add(2*i,2*n+1,a[i],0);
if (i+A+1<=n) add(2*i-1,2*(i+A+1),INF,FA);
if (i+B+1<=n) add(2*i-1,2*(i+B+1),INF,FB);
}
while (spfa(0,2*n+1));
cout<<ans<<endl;
return 0;
}
【BZOJ 1221】 [HNOI2001] 软件开发的更多相关文章
- BZOJ 1221: [HNOI2001] 软件开发
1221: [HNOI2001] 软件开发 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1428 Solved: 791[Submit][Stat ...
- BZOJ 3280: 小R的烦恼 & BZOJ 1221: [HNOI2001] 软件开发
3280: 小R的烦恼 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 399 Solved: 200[Submit][Status][Discuss ...
- BZOJ 1221: [HNOI2001] 软件开发(最小费用最大流)
不知道为什么这么慢.... 费用流,拆点.... --------------------------------------------------------------------------- ...
- bzoj 1221 [HNOI2001] 软件开发 费用流
[HNOI2001] 软件开发 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1938 Solved: 1118[Submit][Status][D ...
- [BZOJ 1221] [HNOI2001] 软件开发 【费用流 || 三分】
题目链接:BZOJ - 1221 题目分析 算法一:最小费用最大流 首先这是一道经典的网络流问题.每天建立两个节点,一个 i 表示使用毛巾,一个 i' 表示这天用过的毛巾. 然后 i 向 T 连 Ai ...
- BZOJ 1221: [HNOI2001] 软件开发【最小费用最大流】
Description 某软件公司正在规划一项n天的软件开发计划,根据开发计划第i天需要ni个软件开发人员,为了提高软件开发人员的效率,公司给软件人员提供了很多的服务,其中一项服务就是要为每个开发人员 ...
- BZOJ 1221 [HNOI2001] 软件开发 费用流_建模
题目描述: 某软件公司正在规划一项n天的软件开发计划,根据开发计划第i天需要ni个软件开发人员,为了提高软件开发人员的效率,公司给软件人员提供了很多的服务,其中一项服务就是要为每个开发人员每天提供 ...
- BZOJ 1221 [HNOI2001] 软件开发(费用流)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1221 [题目大意] 每天对毛巾都有一定的需求ni,每天可以花f价值每条购买毛巾, 当天 ...
- bzoj 1221: [HNOI2001] 软件开发 (网络流)
注意说如果直接从每天的新的连向旧的,那整个图的最大流还是不变,答案就一直会是Σni*f type arr=record toward,next,cap,cost:longint; end; const ...
- 【BZOJ 1221】 1221: [HNOI2001] 软件开发 (最小费用流)
1221: [HNOI2001] 软件开发 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1581 Solved: 891 Description ...
随机推荐
- ORA-12560: TNS: 协议适配器错误(oracle service 已启动)
如果是安装完 oracle 客户端之后才出现的这个问题,请往下看 安装 oracle client 时,会配置一个客户端的监听,如果电脑上之前安装过 oracle service 就会和服务的监听冲突 ...
- 在android平台打印C语言日志
在android平台打印C语言日志 1.操作平台:AS2.0 2.步骤如下: 在C代码中添加如下代码: #define LOG_TAG "我的C语言日志:" #define LOG ...
- using_where, Using temporary ,using_filesort 分享
Using filsort文档中的解释: Mysql需要额外的一次传递,以找出如何按排序顺序检索行,通过根据联接类型浏览所有行并为所有匹配where子句的行保存排序关键字和行的指针来完成排序,然后关键 ...
- git常规使用的命令
注: xxxx代表你的分支名称 1:本地新建一个分支,与远程分支关联: git branch --set-upstream-to origin/xxxx xxxx 2:创建本地分支: git ...
- EF Code First:实体映射,数据迁移,重构
经过EF的<第一篇>,我们已经把数据访问层基本搭建起来了,但并没有涉及实体关系.实体关系对于一个数据库系统来说至关重要,而且EF的各个实体之间的联系,实体之间的协作,联合查询等也都依赖于这 ...
- quick-cocos2dx 之transition.execute()的缓动效果
注:本文图片来源(http://hosted.zeh.com.br/tweener/docs/en-us/misc/transitions.html. 侵权请告知,即刻删除) 什么是缓动, 缓动(ea ...
- gem update --system
gem update --system 修改完gem sources之后,进行gem update: gem update --system 之后的输出: C:\Sites\test01>gem ...
- hdu 3697 Selecting courses (暴力+贪心)
Selecting courses Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 62768/32768 K (Java/Others ...
- linux下配置虚拟域名
linux下配置虚拟域名 1.hosts文件位置! /etc/hosts 2.增加一行 127.0.0.1 xxxxx 3.修改apache中的vhosts vi /etc/httpd/extra/h ...
- 什么是BOM头(字节顺序标记(ByteOrderMark))
在utf-8编码文件中BOM在文件头部,占用三个字节,用来标示该文件属于utf-8编码,现在已经有很多软件识别bom头,但是还有些不能识别bom头,比如PHP就不能识别bom头,这也是用记事本编辑ut ...