嘟嘟嘟

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

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

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. 获取URL中某个参数的值

    JS代码: function getQueryString(name){ var reg = new RegExp("(^|&)" + name + "=([^& ...

  2. springmvc + spring + ibatis + mysql

    1.spring mvc 官网下载:https://repo.spring.io/webapp/#/artifacts/browse/simple/General/libs-release-local ...

  3. 【5】.net WCF 简单实例

    1.创建WCF项目 2.系统自动生成IWcfService // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的接口名“IService1”. [ServiceContra ...

  4. jquery居中窗口-页面加载直接居中

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. mybatis向数据库插入数据 (传入的是一个实体类)

    /** * 插入用户信息 user为实体类 * @param user */ public int insert( User user); //实体类不用@param标注 //mybatis的xml文 ...

  6. 获取页面z-index最大值

    getMaxZIndex = function () { var maxZ = Math.max.apply(null, $.map($('body *'), function(e,n) { if ( ...

  7. sqlserver2008数据库文件降级为sqlserver2005文件

    直接分离附加是不行的. 操作步骤如下: 在sqlserver2008企业管理器中 右键xx数据库->任务->生成脚本 弹出框中勾选 为所选数据库中的所有对象编写脚本 下一步  修改如下图片 ...

  8. content-box跟border-box的区别

    content-box: padding和border不被包含在定义的width和height之内.对象的实际宽度等于设置的width值和border.padding之和,即 ( Element wi ...

  9. Flex和MyEclipse10整合时候需要注意的问题

    1.myeclipse和flex的位数要一致,不能混着安装 2.独立安装完Adobe Flash Builder 4.6 Installer之后,在其的安装文件夹下有一个utilities文件夹下有一 ...

  10. Javascript 多物体运动1

    多物体运动 <!DOCTYPE html><html> <head>  <meta charset="UTF-8">  <ti ...