题面

洛谷

题解

代码

\(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. 1968. [AHOI2005]约数研究【数论】

    Description Input 只有一行一个整数 N(0 < N < 1000000). Output 只有一行输出,为整数M,即f(1)到f(N)的累加和. Sample Input ...

  2. 3、Android-全局大喇叭-广播机制

    所谓的官博机制可以理解成为1对多的概念 即一个喇叭所有的人都能听到(统一范围内) 为了便于及逆行系统级别的消息通知 Android引入了一套广播机制 而且更容易进行实现. 3.1.广播机制的简介 再A ...

  3. Monkeyrunner命令

    1.使用Monkeyrunner脚本命令时,需要导入模块才能使用模块的脚本命令,Monkeyrunner的常用模块有 MonkeyRunner,MonkeyDevice,MonkeyImage,Mon ...

  4. rocketmq命令【转】

    首先进入 RocketMQ 工程,进入/RocketMQ/bin   在该目录下有个 mqadmin 脚本 .  查看帮助:   在 mqadmin 下可以查看有哪些命令    a: 查看具体命令的使 ...

  5. Beta Distribution

    首先思考一个问题: 熟悉棒球运动的都知道有一个指标就是棒球击球率(batting average),就是用一个运动员击中的球数除以击球的总数,我们一般认为0.266是正常水平的击球率,正常范围在0.2 ...

  6. (转)Linux内核基数树应用分析

    Linux内核基数树应用分析 ——lvyilong316 基数树(Radix tree)可看做是以二进制位串为关键字的trie树,是一种多叉树结构,同时又类似多层索引表,每个中间节点包含指向多个节点的 ...

  7. 轻量ORM-SqlRepoEx (十四)最佳实践之Dapper(1)

    简介:SqlRepoEx是 .Net平台下兼容.NET Standard 2.0人一个轻型的ORM.解决了Lambda转Sql语句这一难题,SqlRepoEx使用的是Lambda表达式,所以,对c#程 ...

  8. 爬虫实战:汽车之家配置页面 破解伪元素和混淆JS

    本篇介绍如何破解汽车之家配置页面的伪元素和混淆的JS. ** 温馨提示:如需转载本文,请注明内容出处.** 本文链接:https://www.cnblogs.com/grom/p/9242156.ht ...

  9. JDBC—执行sql语句的通用方法

    /* * 执行 sql的方法集 * delete,insert into ,update */ public static void update(String sql){ Connection co ...

  10. H5页面手机端禁止缩放的正确方式

    H5页面禁止手机端缩放是个常见问题了 首先说meta方式 <meta content="width=device-width, initial-scale=1.0, maximum-s ...