0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:31:59 +00:00

P3154 [CQOI2009]循环赛

https://www.luogu.com.cn/record/85829701
This commit is contained in:
Baoshuo Ren 2022-09-04 10:27:59 +08:00
parent 5b884a0621
commit 84827e9628
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

108
Luogu/P3154/P3154.cpp Normal file
View File

@ -0,0 +1,108 @@
#include <cstdio>
#include <cctype>
const int N = 10;
int n, a[N], s[N], ans;
template <typename T>
void read(T& x) {
x = 0;
char c = getchar();
int f = 1;
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) {
x = x * 10 + (c - '0');
c = getchar();
}
x *= f;
}
void dfs(int x, int y) {
// 当前得分已经大于最终得分
if (s[x] > a[x]) return;
// 如果以后的比赛全赢也小于最后的分数
if (s[x] + (n - y + 1) * 3 < a[x]) return;
if (x == n && s[x] == a[x]) {
ans++;
return;
}
if (y == n) {
int t = a[x] - s[x];
// 最后一场比赛无法凑出 2 分
switch (t) {
case 0: {
s[y] += 3;
dfs(x + 1, x + 2);
s[y] -= 3;
break;
}
case 1: {
s[x] += 1;
s[y] += 1;
dfs(x + 1, x + 2);
s[x] -= 1;
s[y] -= 1;
break;
}
case 3: {
s[x] += 3;
dfs(x + 1, x + 2);
s[x] -= 3;
break;
}
}
return;
}
// x 胜
s[x] += 3;
s[y] += 0;
dfs(x, y + 1);
s[x] -= 3;
s[y] -= 0;
// 平局
s[x] += 1;
s[y] += 1;
dfs(x, y + 1);
s[x] -= 1;
s[y] -= 1;
// y 胜
s[x] += 0;
s[y] += 3;
dfs(x, y + 1);
s[x] -= 0;
s[y] -= 3;
}
int main() {
read(n);
for (int i = 1; i <= n; i++) {
read(a[i]);
}
dfs(1, 2);
printf("%d\n", ans);
return 0;
}