感觉费用流比网络流的图更难想到,要更大胆。
首先由于日期是连续的,所以图中的点是横向排列的。

这道题有点绕道走的意思,由于一类志愿者是可以服务于一段时间,那我们给第i天连出去多条边,第一条边是流向i+1点的,容量为inf-a【i】,费用为0,
若有i 到 其他点t,费用为w, 则连一条(i, t+1, inf,w)的边

跑一遍费用流,算出结果

#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert> /* ⊂_ヽ
  \\ Λ_Λ 来了老弟
   \('ㅅ')
    > ⌒ヽ
   /   へ\
   /  / \\
   レ ノ   ヽ_つ
  / /
  / /|
 ( (ヽ
 | |、\
 | 丿 \ ⌒)
 | |  ) /
'ノ )  Lノ */ using namespace std;
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 bll;
typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int,pii> p3; //priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n' #define boost ios::sync_with_stdio(false);cin.tie(0)
#define rep(a, b, c) for(int a = (b); a <= (c); ++ a)
#define max3(a,b,c) max(max(a,b), c);
#define min3(a,b,c) min(min(a,b), c); const ll oo = 1ll<<;
const ll mos = 0x7FFFFFFF; //
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //
const ll mod = ;
const double esp = 1e-;
const double PI=acos(-1.0);
const double PHI=0.61803399; //黄金分割点
const double tPHI=0.38196601; template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
} inline void cmax(int &x,int y){if(x<y)x=y;}
inline void cmax(ll &x,ll y){if(x<y)x=y;}
inline void cmin(int &x,int y){if(x>y)x=y;}
inline void cmin(ll &x,ll y){if(x>y)x=y;} /*-----------------------showtime----------------------*/ const int maxn = 1e3+;
int a[maxn];
struct E{
int v,val,cost;
int nxt;
}edge[maxn*maxn];
int head[maxn],gtot;
void addedge(int u,int v,int val,int cost){
edge[gtot].v = v;
edge[gtot].val = val;
edge[gtot].cost = cost;
edge[gtot].nxt = head[u];
head[u] = gtot++; edge[gtot].v = u;
edge[gtot].val = ;
edge[gtot].cost = -cost;
edge[gtot].nxt = head[v];
head[v] = gtot++;
} int dis[maxn],pre[maxn],vis[maxn],path[maxn];
bool spfa(int s,int t){
memset(dis,inf, sizeof(dis));
memset(vis, , sizeof(vis));
memset(pre, -, sizeof(pre)); dis[s] = ; vis[s] = ;
queue<int>que;
que.push(s); while(!que.empty()){
int u = que.front(); que.pop();
vis[u] = ;
for(int i=head[u]; ~i; i=edge[i].nxt){
int v = edge[i].v, val = edge[i].val, cost = edge[i].cost;
if(val > && dis[v] > dis[u] + cost){
dis[v] = dis[u] + cost;
pre[v] = u; path[v] = i;
if(vis[v] == ){
vis[v] = ;
que.push(v);
}
}
}
}
return pre[t] != -;
}
int mcmf(int s,int t){
int flow = , cost = ;
while(spfa(s, t)){
int f = inf;
for(int i=t; i!=s; i=pre[i]){
f = min(f, edge[path[i]].val);
}
flow += f;
cost += f * dis[t];
for(int i=t; i!=s; i=pre[i]){
edge[path[i]].val -= f;
edge[path[i]^].val += f;
}
}
return cost;
}
int main(){
memset(head, -, sizeof(head));
int n,m;
scanf("%d%d", &n, &m);
rep(i, , n) scanf("%d", &a[i]);
int s = , t = n+;
addedge(s, , inf, );
addedge(n+, t, inf, );
rep(i, , n) addedge(i, i+, inf - a[i], ); while(m --) {
int u,v,w;
scanf("%d%d%d", &u, &v, &w);
addedge(u, v+, inf, w);
}
printf("%d\n", mcmf(s, t)); return ;
}

P3980 [NOI2008]志愿者招募 费用流 (人有多大胆地有多大产的更多相关文章

  1. P3980 [NOI2008]志愿者招募 (费用流)

    题意:最多1000天 每天需要至少ai个工人施工 有10000种工人可以雇佣 每种工人可以工作si到ti天 雇佣一个的花费是ci 问怎样安排使得施工花费最少 思考:最直白的建模方式 就是每种工人可以和 ...

  2. BZOJ 1061: [Noi2008]志愿者招募 费用流

    1061: [Noi2008]志愿者招募 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=1061 Description 申奥成功后,布布 ...

  3. [BZOJ1061] [Noi2008] 志愿者招募 (费用流)

    Description 申奥成功后,布布经过不懈努力,终于成为奥组委下属公司人力资源部门的主管.布布刚上任就遇到了一个难 题:为即将启动的奥运新项目招募一批短期志愿者.经过估算,这个项目需要N 天才能 ...

  4. [NOI2008]志愿者招募 (费用流)

    大意: $n$天, 第$i$天要$a_i$个志愿者. $m$种志愿者, 每种无限多, 第$i$种工作时间$[s_i,t_i]$花费$c_i$, 求最少花费. 源点$S$连第一天, 容量$INF$ 第$ ...

  5. Vijos1825 NOI2008 志愿者招募 费用流

    Orz ByVoid大神的题解:https://www.byvoid.com/blog/noi-2008-employee/ 学习网络流建图的好题,不难想到线性规划的模型,不过利用模型的特殊性,结合网 ...

  6. 【洛谷】P3980 [NOI2008]志愿者招募

    [洛谷]P3980 [NOI2008]志愿者招募 我居然现在才会用费用流解线性规划-- 当然这里解决的一类问题比较特殊 以式子作为点,变量作为边,然后要求就是变量在不同的式子里出现了两次,系数一次为+ ...

  7. 从多种角度看[BZOJ 1061] [NOI 2008]志愿者招募(费用流)

    从多种角度看[BZOJ 1061] [NOI 2008]志愿者招募(费用流) 题面 申奥成功后,布布经过不懈努力,终于成为奥组委下属公司人力资源部门的主管.布布刚上任就遇到了一个难题:为即将启动的奥运 ...

  8. [NOI2008][bzoj1061] 志愿者招募 [费用流+巧妙的建图]

    题面 传送门 思路 引入:网络流? 看到这道题,第一想法是用一个dp来完成决策 但是,显然这道题的数据并不允许我们进行dp,尤其是有10000种志愿者的情况下 那么我们就要想别的办法来解决: 贪心?这 ...

  9. luogu P3980 [NOI2008]志愿者招募

    传送门 网络流又一神仙套路应用 首先考虑列不等式,设\(x_i\)为第i种人的个数,记\(b_{i,j}\)为第i种人第j天是否能工作,那么可以列出n个不等式,第j个为\(\sum_{i=1}^{m} ...

随机推荐

  1. python Django编写接口并用Jmeter测试

    一.环境准备 python3.6.7 Pycharm 二.创建项目 我这里是在Django项目中新建了个APP,目录结构如下图所示: 那么怎么在已有的Django项目中新建APP并进行配置呢: 2.1 ...

  2. Cordova-iOS SDK封装

    源码编译与制作静态库 下载cordova-ios源码,下载地址为:cordova-ios 解压后使用Xcode进行编译,编译选定模拟器和Generic iOS Device,cmd+B,编译成功(Dy ...

  3. spring注解不支持静态变量注入

    spring注解不支持静态变量注入:今天敲代码  自动配置 配置: Animal.java package study01_autoconfig.beanConfig; import org.spri ...

  4. mysql 查询结果显示行号

    mysql 查询时,不像oracle那样,可以直接用 rownum 显示结果行号. 可以用定义用户变量来实现 set @myrnum = 0; select (@myrnum := @myrnum + ...

  5. Spark 系列(四)—— RDD常用算子详解

    一.Transformation spark 常用的 Transformation 算子如下表: Transformation 算子 Meaning(含义) map(func) 对原 RDD 中每个元 ...

  6. 0x02 递推与递归

    [例题]CH0301 递归实现指数型枚举 #include <iostream> #include <cstdio> #include <algorithm> #i ...

  7. Java 8 Stream实践

    [**前面的话**]Java中的Stream于1.8版本析出,平时项目中也有用到,今天就系统的来实践一下.下面借用重庆力帆队伍中我个人比较喜欢的球员来操作一波,队员的年龄为了便于展示某些api做了调整 ...

  8. 结构型设计模式——适配器模式(Go)

    适配器模式: 适配器模式是用于当别人提供的对象或接口中的方法或者其它属性啥的和我们的重复了,或者看的不顺眼.名字太长了记不住,而将其包装到一个对象中,然后通过你感觉自己舒服的方式或者方法名字去间接的调 ...

  9. 转载 | textarea 在浏览器中固定大小和禁止拖动

    HTML 标签 textarea 在大部分浏览器中只要指定行(rows)和列(cols)属性,就可以规定 textarea 的尺寸,大小就不会改变,不过更好的办法是使用 CSS 的 height 和 ...

  10. 【KakaJSON手册】01_JSON转Model_01_基本用法

    在iOS开发中,后台返回的数据大多是JSON格式,对应地会被网络框架层解析成Swift中的Dictionary.Array.由于数据类型的复杂.字段的繁多,直接使用Dictionary.Array会比 ...