题面

洛谷

题解

代码

\(50pts\)

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; inline int gi() {
register int data = 0, w = 1;
register char ch = 0;
while (ch != '-' && (ch > '9' || ch < '0')) ch = getchar();
if (ch == '-') w = -1 , ch = getchar();
while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
return w * data;
}
int N, go[20];
int a[20][20];
int s[20]; //当前x队获得了多少分
int ans = 0;
int tot = 0;
int score = 0;
void dfs(int x, int y) { //刷到了表的第x行,第y列
if (score > tot) return ;
if (x == N + 1) {
bool F = 1;
for (int i = 1; i <= N; i++)
if (s[i] != go[i]) {
F = 0; break;
}
ans += F;
if (ans == 1000000007) ans = 0;
} else {
//这一盘输了
score += 3;
s[y] += 3;
if (s[y] > go[y]) goto nxt1;
if (s[x] > go[x]) {
score -= 3;
s[y] -= 3;
return ;
}
if (s[x] + 3 * (N - y) < go[x]) goto nxt1;
if (s[y] + 3 * (N - x) < go[y]) {
score -= 3;
s[y] -= 3;
return ;
}
if (y == x - 1) dfs(x + 1, 1);
else dfs(x, y + 1);
nxt1 : { }
score -= 3;
s[y] -= 3;
//这一盘赢了
score += 3;
s[x] += 3;
if (s[x] > go[x]) goto nxt2;
if (s[y] > go[y]) {
s[x] -= 3;
score -= 3;
return ;
}
if (s[y] + 3 * (N - x) < go[y]) goto nxt2;
if (s[x] + 3 * (N - y) < go[x]) {
s[x] -= 3;
score -= 3;
return ;
}
if (y == x - 1) dfs(x + 1, 1);
else dfs(x, y + 1);
nxt2 : { }
s[x] -= 3;
score -= 3;
//这一盘和了
score += 2;
s[x]++, s[y]++;
if (s[x] > go[x] || s[y] > go[y]) {
score -= 2;
s[x]--, s[y]--;
return ;
}
if (s[y] + 3 * (N - x) < go[y]) {
s[x]--, s[y]--;
score -= 2;
return ;
}
if (s[x] + 3 * (N - y) < go[x]) {
s[x]--, s[y]--;
score -= 2;
return ;
}
if (y == x - 1) dfs(x + 1, 1);
else dfs(x, y + 1);
s[x]--, s[y]--;
score -= 2;
}
}
int main () {
N = gi();
for (int i = 1; i <= N; i++) tot += go[i] = gi();
dfs(2, 1);
printf("%d\n", ans);
return 0;
}

\(100pts\)

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
using namespace std;
typedef unsigned long long ull;
#define Mod 1000000007
inline void add(int &x, int y) { x += y; if (x >= Mod) x -= Mod; }
int N, a[20], tmp[20];
map<ull, int> mp;
int dfs(int x, int y) {
if (a[x] > (x - y) * 3) return 0;
int res = 0; ull hs = 0;
if (x == y) {
if (x == 1) return 1;
for (int i = 1; i < x; i++) tmp[i] = a[i];
hs = x - 1; sort(&tmp[1], &tmp[x]);
for (int i = 1; i < x; i++) hs = 27 * hs + tmp[i];
return mp.find(hs) != mp.end() ? mp[hs] : mp[hs] = dfs(x - 1, 1);
}
if (a[x] >= 3) a[x] -= 3, add(res, dfs(x, y + 1)), a[x] += 3;
if (a[x] && a[y]) --a[x], --a[y], add(res, dfs(x, y + 1)), ++a[x], ++a[y];
if (a[y] >= 3) a[y] -= 3, add(res, dfs(x, y + 1)), a[y] += 3;
return res;
}
int main () {
cin >> N;
for (int i = 1; i <= N; i++) cin >> a[i];
sort(&a[1], &a[N + 1], greater<int>());
printf("%d\n", dfs(N, 1));
return 0;
}

【LG3230】[HNOI2013]比赛的更多相关文章

  1. 【BZOJ3139】[HNOI2013]比赛(搜索)

    [BZOJ3139][HNOI2013]比赛(搜索) 题面 BZOJ 洛谷 题解 双倍经验

  2. [HNOI2013]比赛 (用Hash实现记忆化搜索)

    [HNOI2013]比赛 题目描述 沫沫非常喜欢看足球赛,但因为沉迷于射箭游戏,错过了最近的一次足球联赛.此次联 赛共N支球队参加,比赛规则如下: (1) 每两支球队之间踢一场比赛. (2) 若平局, ...

  3. [HNOI2013]比赛 搜索

    [HNOI2013]比赛 搜索. LG传送门 直接暴力有60,考场上写的60,结果挂成40. 考虑在暴力的同时加个记忆化,把剩下的球队数和每支球队的得分情况hash一下,每次搜到还剩\(t\)个队的时 ...

  4. [BZOJ3139][HNOI2013]比赛(搜索)

    3139: [Hnoi2013]比赛 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 1439  Solved: 719[Submit][Status] ...

  5. 【题解】HNOI2013比赛

    [题解][P3230 HNOI2013]比赛 将得分的序列化成样例给的那种表格,发现一行和一列是同时确定的.这个表格之前是正方形的,后来长宽都减去一,还是正方形.问题形式是递归的.这就启示我们可以把这 ...

  6. BZOJ1306 [CQOI2009]match循环赛/BZOJ3139 [Hnoi2013]比赛[dfs剪枝+细节题]

    地址 看数据范围很明显的搜索题,暴力dfs是枚举按顺序每一场比赛的胜败情况到底,合法就累计.$O(3^{n*(n-1)/2})$.n到10的时候比较大,考虑剪枝. 本人比较菜所以关键性的剪枝没想出来, ...

  7. [BZOJ3139][HNOI2013] 比赛

    Description 沫沫非常喜欢看足球赛,但因为沉迷于射箭游戏,错过了最近的一次足球联赛.此次联 赛共N支球队参加,比赛规则如下:  (1) 每两支球队之间踢一场比赛. (2) 若平局,两支球队各 ...

  8. 3139:[HNOI2013]比赛 - BZOJ

    题目描述 Description 沫沫非常喜欢看足球赛,但因为沉迷于射箭游戏,错过了最近的一次足球联赛.此次联赛共N只队伍参加,比赛规则如下: (1) 每两支球队之间踢一场比赛. (2) 若平局,两支 ...

  9. bzoj 3139: [Hnoi2013]比赛

    Description 沫沫非常喜欢看足球赛,但因为沉迷于射箭游戏,错过了最近的一次足球联赛.此次联 赛共N支球队参加,比赛规则如下: (1) 每两支球队之间踢一场比赛. (2) 若平局,两支球队各得 ...

随机推荐

  1. php-fpm配置参数.md

    Global Options pid string PID文件的位置.默认为空.默认路径放在/usr/local/php-fpm/var. error_log string 错误日志的位置.默认:安装 ...

  2. SVM中为何间隔边界的值为正负1

    在WB二面中,问到让讲一下SVM算法. 我回答的时候,直接答道线性分隔面将样本分为正负两类,取平行于线性切割面的两个面作为间隔边界,分别为:wx+b=1和wx+ b = -1. 面试官就问,为什么是正 ...

  3. Python 模块化 from .. import 语句资源搜索顺序 (三)

    接着上一篇文章最后的import子句资源搜索顺序,我们来写几个例子了解下. 例一. #test1.py x = 123 #test.py import test1 print(dir()) print ...

  4. concatenate函数

    numpy.concatenate((a1, a2, ...), axis=0) Join a sequence of arrays along an existing axis.(按轴axis连接a ...

  5. UVALive - 6837 Kruskal+一点性质(暴力枚举)

    ICPC (Isles of Coral Park City) consist of several beautiful islands. The citizens requested constru ...

  6. 阅读Deep Packet Inspection based Application-Aware Traffic Control for Software Defined Networks

    Deep Packet Inspection based Application-Aware Traffic Control for Software Defined Networks Globlec ...

  7. ovs的卸载删除

    参考博客1 参考博客2 需要更新.重装ovs时需要先卸载. 删除网桥.端口 ovs-vsctl del-br 交换机名 ovs-vsctl del-port 交换机名 端口名(网卡名) 关闭服务 su ...

  8. STM32F103 ucLinux开发之三(内核启动后不正常)(完结)

    STM32F103 ucLinux内核没有完全启动 从BOOT跳转到内核后,执行一长段的汇编语言,然后来到startkernel函数,开启C语言之旅. 但是内核输出不正常,如下所示: Linux ve ...

  9. MyBatis配置数据库连接

    <environments default="default"> <environment id="default"> <tran ...

  10. JavaScript互斥锁案例

    朋友今天问起来关于JS中多个函数共享同一个全局变量时,顺序调用执行的函数,前者修改了全局变量值,后调用的函数访问时却为undefined. 前不久开发项目过程中,队友也遇到了同样的问题,索性就写份博客 ...