嘟嘟嘟

很显然是一道最小割模型。

做完几道题后。图的大概就能想出来了:

1.对于每一个动物,如果是0,就和s连一条边,否则向t连一条边。

2.对于每一个任务,题中要求最大利润,可以转化成最小损失。

  (1)如果都要变成1,就向汇点连一条w +g(如果有的话)的边;否则从源点连一条w +g的边。接下来

  (2)对于任务中涉及的每一个点,刚开始我想如果任务要变成1,而他本身还是1就不连边,否则连一条INF的边,然后我就发现任务之间是互相影响的,而这种方式体现不出来,然后我就想不出来了……

     题解是这么说的:如果这个任务是0,就向所有涉及到的点连边,否则这些点向他连边,然后我就画了一个图,发现好像还真是这么回事:

如果我们要达成任务1的话,就要割掉(2->t), (3->t)两条边,但是图还是联通的,因此还得割掉([2]->t)的边,也就同时说明了任务2不可达成。

 #include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define rg register
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-;
const int maxn = 1.2e4 + ;
inline ll read()
{
ll ans = ;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) {last = ch; ch = getchar();}
while(isdigit(ch)) {ans = ans * + ch - ''; ch = getchar();}
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < ) x = -x, putchar('-');
if(x >= ) write(x / );
putchar(x % + '');
} int n, m, t;
int g, val[maxn], sum = ;
bool a[maxn]; struct Edge
{
int from, to, cap, flow;
};
vector<Edge> edges;
vector<int> G[maxn];
void addEdge(int from, int to, int w)
{
edges.push_back((Edge){from, to, w, });
edges.push_back((Edge){to, from, , });
int sz = edges.size();
G[from].push_back(sz - );
G[to].push_back(sz - );
} int dis[maxn];
bool bfs()
{
Mem(dis, ); dis[] = ;
queue<int> q; q.push();
while(!q.empty())
{
int now = q.front(); q.pop();
for(int i = ; i < (int)G[now].size(); ++i)
{
Edge& e = edges[G[now][i]];
if(!dis[e.to] && e.cap > e.flow)
{
dis[e.to] = dis[now] + ;
q.push(e.to);
}
}
}
return dis[t];
}
int cur[maxn];
int dfs(int now, int res)
{
if(now == t || res == ) return res;
int flow = , f;
for(int& i = cur[now]; i < (int)G[now].size(); ++i)
{
Edge& e = edges[G[now][i]];
if(dis[e.to] == dis[now] + && (f = dfs(e.to, min(res, e.cap - e.flow))) > )
{
e.flow += f;
edges[G[now][i] ^ ].flow -= f;
flow += f; res -= f;
if(res == ) break;
}
}
return flow;
} int minCut()
{
int flow = ;
while(bfs())
{
Mem(cur, );
flow += dfs(, INF);
}
return flow;
} int main()
{
n = read(), m = read(), g = read();
t = n + m + ;
for(int i = ; i <= n; ++i) a[i] = (bool)read();
for(int i = ; i <= n; ++i)
{
int x = read();
if(a[i]) addEdge(i, t, x);
else addEdge(, i, x);
}
for(int i = ; i <= m; ++i)
{
int op = read(), w = read(), k = read();
sum += w;
for(int j = ; j <= k; ++j)
{
int id = read();
if(op) addEdge(id, i + n, INF);
else addEdge(i + n, id, INF);
}
int flg = read();
if(op) addEdge(i + n, t, w + flg * g);
else addEdge(, i + n, w + flg * g);
}
write(sum - minCut()); enter;
return ;
}

CF311E Biologist的更多相关文章

  1. 【CF331E】Biologist(网络流,最小割)

    [CF331E]Biologist(网络流,最小割) 题面 洛谷 翻译: 有一个长度为\(n\)的\(01\)串,将第\(i\)个位置变为另外一个数字的代价是\(v_i\). 有\(m\)个要求 每个 ...

  2. 【CodeForces】【311E】Biologist

    网络流/最大权闭合图 题目:http://codeforces.com/problemset/problem/311/E 嗯这是最大权闭合图中很棒的一道题了- 能够1A真是开心-也是我A掉的第一道E题 ...

  3. CF 331 E. Biologist

    CF 331 E. Biologist 题目描述 题目大意:有\(n\)个点,初始时每个点为黑色或者白色,你可以花费\(v_i\)的代价将一个点反色.然后你有许多计划,每个计划要求一个点集中的所有点为 ...

  4. So you want to be a computational biologist?

    So you want to be a computational biologist? computational biology course

  5. Codeforces 311.E Biologist

    E. Biologist time limit per test 1.5 seconds memory limit per test 256 megabytes input standard inpu ...

  6. Codeforces 311E Biologist

    Discription SmallR is a biologist. Her latest research finding is how to change the sex of dogs. In ...

  7. FreeMarker中文API手册(完整)

    FreeMarker概述 FreeMarker是一个模板引擎,一个基于模板生成文本输出的通用工具,使用纯Java编写 FreeMarker被设计用来生成HTML Web页面,特别是基于MVC模式的应用 ...

  8. HDU-4057 Rescue the Rabbit(AC自动机+DP)

    Rescue the Rabbit Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  9. FreeMark学习(一)

    FreeMarker是一个模板引擎,一个基于模板生成文本输出的通用工具,使用纯Java编写 FreeMarker被设计用来生成HTML Web页面,特别是基于MVC模式的应用程序 虽然FreeMark ...

随机推荐

  1. Spring - 几种RPC模型的使用与比较

    Spring中,用JMS搞RPC时会用到: org.springframework.jms.remoting.JmsInvokerServiceExporter org.springframework ...

  2. 二:Redis数据类型

    一.nosql(非关系性数据库): mongoDB hbase redis nulch hive pig mahout zookeeper 二:redis 数据类型 1.存储string: 常用命令 ...

  3. Excel批量生成条形码

    项目要求需要将信息做成条形码的形式,以便通过手持设备直接查看信息,因本次项目信息为固定信息,不需随机生成,故采用本方法: 代码随机生成二维码暂时没有接触,后续有时间会研究 步骤: 1.新建 Excel ...

  4. Java泛型拾遗

    先上百度百科的解释 泛型是Java SE 1.5的新特性,泛型的本质是参数化类型,也就是说所操作的数据类型被指定为一个参数.这种参数类型可以用在类.接口和方法的创建中,分别称为泛型类.泛型接口.泛型方 ...

  5. 给div加上padding和border,如何不让div整体改变

    最近要入门H5,遇到很多困惑,所以,每解决一个,我就要写在博客里,以防忘记! 给div加上padding和border,如何不让div整体改变? 如果想要实现这样的效果,只需要在这个div块中写入 b ...

  6. PL/SQL 快速连接数据库

    打开PL/SQL 登录窗口,在数据库地址写入 服务器名:端口号/sid 即可, 例如: 192.168.100.100:1521/test

  7. Codeforces183D T-shirt

    传送门 这题好神啊……(然而我连每种物品贡献独立都没看出来…… 首先$O(n^2 m)$的DP肯定都会写,然后可以发现每种物品一定是选得越多再选一个的收益就越低,因此可以用一个堆维护当前收益最高的物品 ...

  8. 关于Function原型对象和Object原型对象的一些疑惑

    网上有一道美团外卖的面试题是这样的: Function.prototype.a = 'a'; Object.prototype.b = 'b'; function Person(){}; var p ...

  9. Excellent JD

    Job description About the role We are looking for a talented engineer who has excellent cloud skills ...

  10. 十五、css3 Filter--滤镜

    如何实现下图的效果-—这里就用到了滤镜 给灰色弹框这个标签元素加“伪类”如下: #nearStoreContent .popChoose li:before { 1. z-index:; 2. pos ...