最小值最大,就二分判断。

map[i] = '0'+map[i];这样更方便

每个点拆成i,i’,  S连i,cap为a[i],i’连T,cap为1(保证至少剩一个)或mid。

i,i’ ,a[i]

i->j’,   inf    //把i连到j就WA了...所以题目的意思大概是只能移动到相邻点?

判断一下border

#include<iostream>
#include<queue>
#include<cmath>
#include<cstring>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
const int maxn = , INF = 0x3f3f3f3f;
int a[maxn], border[maxn];
string map[maxn];
struct Edge
{
int from, to, cap, flow;
Edge(int u, int v, int c, int f) :from(u), to(v), cap(c), flow(f) {}
};
struct EdmondsKarp
{
int n, m;
vector<Edge> edges;
vector<int> G[maxn];
int a[maxn];
int p[maxn]; void init(int n)
{
this->n = n;
for (int i = ; i < n; i++)
{
G[i].clear();
}
edges.clear();
memset(p, , sizeof(p));//²»ÐèÒª£¿
}
void AddEdge(int u, int v, int c)
{
edges.push_back(Edge(u, v, c, ));
edges.push_back(Edge(v, u, , ));
m = edges.size();
G[u].push_back(m - );
G[v].push_back(m - );
}
int MaxFlow(int s, int t)
{
int flow = ;
for (;;)
{
memset(a, , sizeof(a));
queue<int> Q;
Q.push(s);
a[s] = INF;
while (!Q.empty())
{
int u = Q.front();
Q.pop();
for (int i = ; i < G[u].size(); i++)
{
Edge& e = edges[G[u][i]];
if (!a[e.to] && e.cap > e.flow)
{
a[e.to] = min(a[u], e.cap - e.flow);
Q.push(e.to);
p[e.to] = G[u][i];
}
}
if (a[t])
break;
}
if (!a[t])
break;
for (int i = t; i != s; i = edges[p[i]].from)
{
edges[p[i]].flow += a[t];
edges[p[i] ^ ].flow -= a[t];
}
flow += a[t];
}
return flow;
}
}E; int Build(int val,int N)
{
for (int i = ; i <= N; i++)
{
if (!a[i])
continue;
E.AddEdge(, i, a[i]);
E.AddEdge(i, i + N, a[i]);
for (int j = ; j <= N; j++)
if (map[i][j] == 'Y')
{
if (!a[j])
border[i] = true; //border
else
E.AddEdge(i, j + N, INF);
}
}
int ans = ;
for (int i = ; i <= N; i++)
if (border[i])
{
E.AddEdge(i + N, * N + , val);
ans += val;
}
else if (a[i])
{
E.AddEdge(i + N, * N + , );
ans++;
};
return ans;
}
void solve(int n)
{
int a, b, ans;
int l = , r = ;
while (l<r)
{
E.init( * n + );
int mid = l+(r-l)/;
a = Build(mid, n);
b = E.MaxFlow(, * n + );
if (a == b)
{
l = mid + ;
ans = mid;
}
else r = mid;
}
cout << ans << endl;
} void input(int n){
memset(a, , sizeof(a));
memset(border, , sizeof(border));
for (int i = ; i < maxn; i++)
map[i].clear(); for (int i = ; i <= n; i++)
cin >> a[i];
for (int i = ; i <= n; i++)
{
cin >> map[i];
map[i] = ''+map[i];
}
} int main()
{
int T;
cin >> T;
while (T--)
{
int n;
cin >> n;
input(n);
solve(n);
}
return ;
}

uva12264 Risk的更多相关文章

  1. UVa12264 Risk(最大流)

    题目 Source https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  2. Risk UVA - 12264 拆点法+最大流+二分 最少流量的节点流量尽量多。

    /** 题目:Risk UVA - 12264 链接:https://vjudge.net/problem/UVA-12264 题意:给n个点的无权无向图(n<=100),每个点有一个非负数ai ...

  3. PHP Datatype Conversion Safety Risk、Floating Point Precision、Operator Security Risk、Safety Coding Principle

    catalog . 引言 . PHP operator introduction . 算术运算符 . 赋值运算符 . 位运算符 . 执行运算符 . 递增/递减运算符 . 数组运算符 . 类型运算符 . ...

  4. Linux fork()、exec() Hook Risk、Design-Principle In Multi-Threadeed Program

    目录 . Linux exec指令执行监控Hook方案 . 在"Multi-Threadeed Program"环境中调用fork存在的风险 . Fork When Multi-T ...

  5. Threat Risk Modeling Learning

    相关学习资料 http://msdn.microsoft.com/en-us/library/aa302419(d=printer).aspx http://msdn.microsoft.com/li ...

  6. Stakeholder Risk Management

    In this article we'll address the people swirling around your project: stakeholders. You'll find som ...

  7. 10 Golden Rules of Project Risk Management

    The benefits of risk management in projects are huge. You can gain a lot of money if you deal with u ...

  8. zoj 1221 Risk Flory

    博客开了快半年了- -学习编程也快1年半了,觉得空空的不太好看,刚好最近开始练习ACM了,就来做一个简单的ACM学习笔记吧,纪念的第一题zol 1221 Risk 风险游戏(个人觉得是这样翻- -翻译 ...

  9. UVa 567: Risk

    这是一道很简单的图论题,只要使用宽度优先搜索(BFS)标记节点间距离即可. 我的解题代码如下: #include <iostream> #include <cstdio> #i ...

随机推荐

  1. 爬虫代码实现六-Queue队列实现循环抓取

    StartDSJCount : package com.dajiangtai.djt_spider.start; import java.util.List;import java.util.Queu ...

  2. UVaLive 3695 Distant Galaxy (扫描线)

    题意:给平面上的 n 个点,找出一个矩形,使得边界上包含尽量多的点. 析:如果暴力那么就是枚举上下边界,左右边界,还得统计个数,时间复杂度太高,所以我们考虑用扫描线来做,枚举上下边界, 然后用其他方法 ...

  3. 梦工厂实验室 取石子之fans 博弈

    问题 D: 取石子之fans 时间限制: 1 Sec  内存限制: 64 MB提交: 57  解决: 26[提交][状态][讨论版] 题目描述 Yougth和Hrdv玩一个游戏,拿出n个石子摆成一圈, ...

  4. Bootstrap 自适应排列顺序

    一.前用 我们在做一些页面的设计时,总会想到自适应的问题.其实 Bootstrap 框架就很好的融合这个问题了.下面是我学习 Bootstrap 的总结. 二.问题来源 我为什么会遇见这个问题,是因为 ...

  5. C# in查询

    一.前言 在做项目中,我们会经常使用到 in 查询语句.那么如果我们用 EF 和 Linq 怎么写?接下来看代码 二.实例 我使用的是区域查询的例子,基本的 sql 语句如下: SELECT * FR ...

  6. Linux which 查找命令

    在学习 兄弟连 linux教学视频 的时候,我将所学的 linux 命令记录在我的博客中,方便自己查阅. 权限管理命令: which 基础的命令 命令名称:which 命令的所在路径:/usr/bin ...

  7. laravel V层引入css 和js方法

    引入css  默认引入public目录 <link rel="stylesheet" href="{{URL::asset('css/xxx.css')}}&quo ...

  8. 如何在内网打洞使得能暴露mstsc端口

    说明: 1.目标机器Target,有全部控制权,其所处网络无法向外网暴露端口,但是已知Target的外网地址:Target_internet_addr 2.交换机器Exchange,有全部控制权,其所 ...

  9. hyperledger fabric 1.0.5 分布式部署 (一)

    环境是个人虚拟机ubuntu 16.04 64 位版本 前期用户需要先安装好:gcc.g++.git 软件 安装 golang 首先给环境安装一个 go 语言环境,版本最好在1.8 以上 golang ...

  10. Mybatis思

    站在巨人的肩膀上,感谢! mybatis源码分析之Mapper代理实现分析 2017年11月21日 23:39:04 huangshanchun 阅读数:277    版权声明:欢迎转载,如有不足之处 ...