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

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. Laravel框架之Session操作

    //设置session里的值 public function session1(Request $request){ //1.HTTP request session(); /*$request-&g ...

  2. 如何实现Vue已经弃用的$dispatch和$broadcast方法?

    对于父子(含跨级)传递数据的通信方式,Vue.js 并没有提供原生的 API 来支持,而是推荐使用大型数据状态管理工具 Vuex,但 Vuex 对于小型项目来说用起来真的很麻烦. 在 Vue.js 1 ...

  3. 一张图入门git系列

    github地址:https://github.com/521xueweihan/git-tips

  4. 51nod 1449 砝码称重【天平/进制】

    题意: 给你w,n,问你在w^0,w^1,w^2...各种一个,问你能不能用这些砝码和重量为m的东西放在天平上使得天平平衡: 思路: 这个很容易联想到进制: 如果把m放在是一边的话,其实对于砝码就是纯 ...

  5. NGUI研究院之UISprite和UITexture浅谈

    NGUI的三大组件,UILabel.UISprite.UITexture,它们三个同时都继承UIWidget.先回到一个很郁闷的话题上,到底是优化DrawCall还是优化内存. UISprite : ...

  6. Ruby编程实践

    命令 常量大写 类名和模块名首字母大写,驼峰法,MyClass,Person 方法名小写,ruby中末尾添加符号特殊含义:destroyMethod!表示这个方法具有破坏性:isPrime?表示返回b ...

  7. [Xcode 实际操作]七、文件与数据-(23)UI Testing系统界面测试功能的使用

    目录:[Swift]Xcode实际操作 本文将演示UI Testing系统界面测试功能的使用. 如果项目中尚未引入界面测试功能,请点击项目属性面板->[General]面板左下角的[+]图标 - ...

  8. perl 安装LOG4perl 模块

    环境信息 ubuntu 12.04 64位 桌面版 Log-Log4perl 的介绍网址:http://search.cpan.org/~mschilli/Log-Log4perl-1.49/lib/ ...

  9. 黑马函数式接口学习 Stream流 函数式接口 Lambda表达式 方法引用

  10. mysql ERROR 2003 (HY000): Can't connect to MySQL server on '' (10060

    关闭防火墙即可连接成功: systemctl stop firewalld