P3701 主主树
Sol
还是阅读理解题。
显然可以把加生命的部分可以直接加到血量上。
然后就是每个人之多被使用血量次,直接多重匹配即可。
Code
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define pf push_front
#define desktop "C:\\Users\\incra\\Desktop\\"
#define IOS ios :: sync_with_stdio (false),cin.tie (0),cout.tie (0)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> PII;
const int dx[] = {1,0,-1,0},dy[] = {0,-1,0,1};
template <typename T1,typename T2> bool tomax (T1 &x,T2 y) {
if (y > x) return x = y,true;
return false;
}
template <typename T1,typename T2> bool tomin (T1 &x,T2 y) {
if (y < x) return x = y,true;
return false;
}
LL power (LL a,LL b,LL p) {
LL ans = 1;
while (b) {
if (b & 1) ans = ans * a % p;
a = a * a % p;
b >>= 1;
}
return ans;
}
int fastio = (IOS,0);
#define endl '\n'
#define puts(s) cout << (s) << endl
const int N = 210,M = 40410,INF = 1e8;
int n,m,s,t;
pair <char,int> a[N],b[N];
int h[N],e[M],ne[M],w[M],idx;
int d[N],q[N],cur[N];
int mp[128][128];
void add_edge_ (int a,int b,int c) {
e[idx] = b;
w[idx] = c;
ne[idx] = h[a];
h[a] = idx++;
}
void add_edge (int a,int b,int c) {
add_edge_ (a,b,c),add_edge_ (b,a,0);
}
bool BFS () {
memset (d,-1,sizeof (d));
int hh = 0,tt = -1;
q[++tt] = s;
d[s] = 0;
cur[s] = h[s];
while (hh <= tt) {
int u = q[hh++];
for (int i = h[u];~i;i = ne[i]) {
int v = e[i];
if (d[v] == -1 && w[i]) {
d[v] = d[u] + 1;
q[++tt] = v;
cur[v] = h[v];
if (v == t) return 1;
}
}
}
return 0;
}
int maxflow (int u,int lim) {
if (u == t) return lim;
int ans = 0;
for (int i = cur[u];~i && ans < lim;i = ne[i]) {
cur[u] = i;
int v = e[i];
if (d[v] == d[u] + 1 && w[i]) {
int tmp = maxflow (v,min (lim - ans,w[i]));
if (!tmp) d[v] = -1;
ans += tmp,w[i] -= tmp,w[i ^ 1] += tmp;
}
}
return ans;
}
int dinic () {
int ans = 0,flow;
while (BFS ()) {
while (flow = maxflow (s,INF)) ans += flow;
}
return ans;
}
void mian () {
memset (h,-1,sizeof (h));
mp['W']['Y'] = 1;
mp['W']['E'] = 1;
mp['J']['W'] = 1;
mp['J']['H'] = 1;
mp['E']['Y'] = 1;
mp['E']['J'] = 1;
mp['Y']['H'] = 1;
mp['Y']['J'] = 1;
mp['H']['W'] = 1;
mp['H']['E'] = 1;
cin >> n >> m;
s = 2 * n + 1,t = s + 1;
int cnta = 0,cntb = 0;
for (int i = 1;i <= n;i++) {
string s;
cin >> s;
a[i].x = s[0];
cnta += a[i].x == 'Y';
}
for (int i = 1;i <= n;i++) {
string s;
cin >> s;
b[i].x = s[0];
cntb += b[i].x == 'Y';
}
for (int i = 1;i <= n;i++) cin >> a[i].y;
for (int i = 1;i <= n;i++) cin >> b[i].y;
for (int i = 1;i <= n;i++) {
for (int j = 1;j <= n;j++) {
if (mp[a[i].x][b[j].x]) add_edge (i,j + n,1);
}
}
for (int i = 1;i <= n;i++) add_edge (s,i,a[i].y + (a[i].x == 'J' ? cnta : 0)),add_edge (i + n,t,b[i].y + (b[i].x == 'J' ? cntb : 0));
cout << min (dinic (),m) << endl;
}
int main () {
int T = 1;
// cin >> T;
while (T--) mian ();
return 0;
}

浙公网安备 33010602011771号