srm 557

250


Description

在二维坐标轴上从$(0,h_0)$走到$(n, h_n)$,走一次在x轴上前进一个单位长度,在y轴上上升或者下降一个单位长度
现在已知中间的某段连续区域的走法(只由’U’和’D’构成的不超过50的字符串)
问是否在保证最低点不低于0的情况下成功走到终点。

Solution

判断连续一段最低点到哪里,前面补$U$即可,其余部分判判奇偶随便搞搞就行了

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> pii;
struct FoxAndMountainEasy {
string possible(int n, int h0, int hn, string s) {
int l = s.size();
int mn = 0, now = 0;
for (int i = 0; i < l; ++i) {
if (s[i] == 'U') ++now;
else --now;
mn = min(mn, now);
}
mn = h0 + mn;
int del = hn - h0 - now;
n -= l;
if (mn < 0) del += mn, n += mn;
if (abs(del) > n || n < 0) return "NO";
int t = del - n;
if (t & 1) return "NO";
return "YES";
}
};

550


Description

一张普通图,$50*50$,可能有自环。初始全白
给一个闭包矩阵,每次挑一个点染成灰色则它可达的点全黑,求最多能有多少点变灰

Solution

所求即最长反链,根据dilworth定理,即为最大反链大小等于最少划分成的链数
即求最小可相交路径覆盖,求个闭包$|V|-最大匹配$即为答案

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <bits/stdc++.h>//dilworth
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> pii;
const int N = 55;
int n, l[N];
bool g[N][N], v[N];
struct Incubator {
bool can(int u) {
for (int i = 0; i < n; ++i)
if (g[u][i] && !v[i]) {
v[i] = 1;
if (l[i] == -1 || can(l[i])) {
l[i] = u;
return 1;
}
}
return 0;
}
int maxMagicalGirls(vector <string> s) {
n = s.size();
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
g[i][j] = s[i][j] == 'Y';
for (int k = 0; k < n; ++k)
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
g[i][j] |= g[i][k] & g[k][j];
int t = 0;
memset(l, -1, sizeof(l));
for (int i = 0; i < n; ++i) {
memset(v, 0, sizeof(v));
if (can(i)) ++t;
}
return n - t;
}
};