题面

洛谷

题解

代码

\(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. PhoneGap模仿微信摇一摇功能

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  2. UVa 10288 - Coupons(数学期望 + 递推)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  3. node.js的npm命令常见错误及解决方案

    使用npm命令进行模块安装的时候场出现各种错误,本文总结我所遇到的各种错误,并提供解决方案.(大部分内容为网上收集) 首先使用淘宝 NPM 镜像 大家都知道国内直接使用 npm 的官方镜像是非常慢的, ...

  4. 《metasploit渗透测试魔鬼训练营》靶机演练之第五章实战案例KingView 6.53版本CVE-2011-0406漏洞

    在一个笔记本上开两个虚拟机有点卡,而且太麻烦,就把metasploit的目标靶机放在别的机器上了,ip自己配置了一下, 目标主机:192.168.137.254 入侵机:192.168.137.253 ...

  5. Kali-linux攻击路由器

    前面介绍的各种工具,都是通过直接破解密码,来连接到无线网络.由于在一个无线网络环境的所有设备中,路由器是最重要的设备之一.通常用户为了保护路由器的安全,通常会设置一个比较复杂的密码.甚至一些用户可能会 ...

  6. map详讲<二>

    查找元素: Map可以根据健来查找元素,提供方法find(key),如果是这个健对应的元素存在,则返回的是这个健的迭代器iterator,否则返回的是std::end(): 使用find()函数有点笨 ...

  7. Beta Distribution

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

  8. vue04-动画、组件

    一.vue中使用动画 文档:https://cn.vuejs.org/v2/guide/transitions.html 1. Vue 中的过渡动画 <!DOCTYPE html> < ...

  9. 生成Html 测试报告

    1.引入HTMLTestRunner 下载HTMLTestRunner.py 从http://tungwaiyip.info/software/HTMLTestRunner.html 将下载的HTML ...

  10. Maven 高级应用

    Maven 的高级应用主要体现在 ==依赖==,==聚合==,==继承== * 依赖 就是在当前项目的pom.xml 总引入依赖的坐标 最最经常用到的 <dependencies> < ...