题面

洛谷

题解

代码

\(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. 死磕salt系列-salt 故障汇总

    这里将salt使用过程中遇到的所有的故障进行一个汇总. grains 匹配后多了一个列表 salt-master中配置jinja模板来匹配自定义的grins. vim /etc/salt/minion ...

  2. ERROR: Repository not found. ////Git, but is not registered in the Settings.

    1.ERROR: Repository not found. 这个问题是因为在你推送的github账户中,并没有这个Repository. 解决方法: 1)检查自己的github中的Repositor ...

  3. druid相关资料

    官方资料直达地址: Druid 首页 https://github.com/alibaba/druid/wiki/%E9%A6%96%E9%A1%B5 Druid 常见问题 https://githu ...

  4. linux 下 chkconfig安装与使用详解

    chkconfig 安装 开始的时候因为Raspbian的原因,系统是不自带chkconfig这个命令的, root@raspberrypi:~# chkconfig-bash: chkconfig: ...

  5. Linux Shell常用技巧(十二)

    二十三. Bash Shell编程:  1.  读取用户变量:    read命令是用于从终端或者文件中读取输入的内建命令,read命令读取整行输入,每行末尾的换行符不被读入.在read命令后面,如果 ...

  6. EJB到底是什么?---通俗易懂,简单明了

    EJB到底是什么?   1. 我们不禁要问,什么是"服务集群"?什么是"企业级开发"? 既然说了EJB 是为了"服务集群"和"企业 ...

  7. C# WinForm开发系列 - ListBox/ListView/Panel【zz】

    原文传送:http://www.cnblogs.com/peterzb/archive/2009/06/18/1505424.html 1.ColorListBox   ColorListBox.zi ...

  8. 从对集合数据去重到Distinct源码分析

    今天在写代码的时候要对数据进行去重,正打算使用Distinct方法的时候,发现这个用了这么久的东西,竟然不知道它是怎么实现的,于是就有了这篇文章. 使用的.net core2.0 1.需求 假如我们有 ...

  9. linux下安装protobuf及cmake编译

    一.protobuf 安装 protobuf版本:2.6.1 下载地址:https://github.com/google/protobuf/archive/v2.6.1.zip 解压之后进入目录 修 ...

  10. [译]C语言实现一个简易的Hash table(7)

    上一章我们讲了如何根据需要动态设置hash表的大小,在第四章中,我们使用了双重哈希来解决hash表的碰撞,其实解决方法有很多,这一章我们来介绍下其他方法. 本章将介绍两种解决hash表碰撞的方法: 拉 ...