Miners 矿工配餐

题目大意:矿工配餐

状态显然,\(f[p][i][j][k][z]\)当前送第i辆车,第一个矿前两次送i和j,第二个前两次送k和z

转移很容易啊,不动脑子也知道...

就是个滚动数组

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <bits/stdc++.h>
#define int long long
#define ll long long
using namespace std;

const int N = 1e5 + 66;

char s[N]; int n, res, cur;
int vis[4], f[2][4][4][4][4];

inline int yhm_turn(char ch)
{
if (ch == 'M') return 1;
if (ch == 'B') return 2;
return 3;
}

inline int yhm_func(int a, int b, int c)
{
vis[1] = vis[2] = vis[3] = 0;
vis[a] = vis[b] = vis[c] = 1;
return vis[1] + vis[2] + vis[3];
}

inline void yhm_max(int &a, int b)
{
if (a < b) a = b;
return;
}

signed main()
{
int i, j, k, z, p;
n = read(), scanf("%s", s);
memset(f, -1, sizeof f);
f[0][0][0][0][0] = 0;
for (p = 0; p < n; ++ p)
{
for (i = 0; i <= 3; ++ i) for (j = 0; j <= 3; ++ j)
for (k = 0; k <= 3; ++ k) for (z = 0; z <= 3; ++ z)
{
int x = cur, y = cur ^ 1;
if (f[x][i][k][j][z] == -1) continue;
int now, val;
now = yhm_turn(s[p]);
val = yhm_func(i, k, now);
yhm_max(f[y][now][i][j][z], f[x][i][k][j][z] + val);
val = yhm_func(j, z, now);
yhm_max(f[y][i][k][now][j], f[x][i][k][j][z] + val);
}
cur ^= 1;
}

for (i = 0; i <= 3; ++ i) for (j = 0; j <= 3; ++ j)
for (k = 0; k <= 3; ++ k) for (z = 0; z <= 3; ++ z)
yhm_max(res, f[cur][i][k][j][z]);
put(res);
return 0;
}

后记:

细节真jb多