TopCoder14580: EllysRPS
题意
\(yyb\)要去与\(m\)\((m\le100)\)个人玩游戏
由于\(yyb\)忙着切大火题,他没有太多的精力浪费在游戏上
所以仁慈的\(yyb\)决定放\(m\)个人一条生路,不吊打他们
然而\(yyb\)为了维护自己红太阳的形象,不能输,所以他希望与每个人玩游戏都能是平局
游戏很简单,就是石头剪刀布,\(yyb\)会与每个人玩\(n(n\le 20)\)场
只要双方赢的次数相同就视为平局
\(yyb\)非常的强,所以大家每一场比赛想出什么\(yyb\)一眼就看出来了
每个人的策略都是一个长度为\(n\)的序列
然后他觉得能用同一个长度为\(n\)的策略序列与每个人打平局
然而\(yyb\)并不满足与这些,他想知道自己有多少种方式打平,这样他就能知道别人比自己弱多少,从而增长自己的淫威
正如大家所知,\(yyb\)秒题入魔,懒得去想这个\(naive\)的比赛
所以请比他弱的你来帮他求出这个方案数
Sol
\(meet \ in \ the \ midlle\)
爆搜,把状态开\(vector\)压进\(map\)查询
# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
typedef vector <int> vi;
IL int Input(){
RG int x = 0, z = 1; RG char c = getchar();
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x * z;
}
int win[3][3] = {{0, -1, 1}, {1, 0, -1}, {-1, 1, 0}};
int n, m, a[105][25], b[25], mid;
vi tmp;
map <vi, int> t;
ll ans;
IL void Record(){
tmp.clear();
for(RG int i = 1; i <= m; ++i){
RG int cnt = 0;
for(RG int j = 1; j <= mid; ++j) cnt += win[a[i][j]][b[j]];
tmp.push_back(cnt);
}
++t[tmp];
}
IL void Dfs1(RG int l){
if(l > mid){
Record();
return;
}
for(RG int i = 0; i < 3; ++i) b[l] = i, Dfs1(l + 1);
}
IL void Calc(){
tmp.clear();
for(RG int i = 1; i <= m; ++i){
RG int cnt = 0;
for(RG int j = mid + 1; j <= n; ++j) cnt -= win[a[i][j]][b[j]];
tmp.push_back(cnt);
}
ans += t[tmp];
}
IL void Dfs2(RG int l){
if(l > n){
Calc();
return;
}
for(RG int i = 0; i < 3; ++i) b[l] = i, Dfs2(l + 1);
}
IL ll Solve(){
mid = (1 + n) >> 1;
Dfs1(1), Dfs2(mid + 1);
return ans;
}
class EllysRPS{
public:
ll getCount(vector <string> s){
m = s.size(), n = s[0].size();
for(RG int i = 1; i <= m; ++i)
for(RG int j = 1; j <= n; ++j)
if(s[i - 1][j - 1] == 'R') a[i][j] = 0;
else a[i][j] = (s[i - 1][j - 1] == 'S') + 1;
return Solve();
}
};
TopCoder14580: EllysRPS的更多相关文章
- Meet in the middle学习笔记
Meet in the middle(MITM) Tags:搜索 作业部落 评论地址 PPT中会讲的很详细 当搜索的各项互不影响(如共\(n\)个物品前\(n/2\)个物品选不选和后\(n/2\)个物 ...
随机推荐
- Centos7.4下安装Redis5.0
一.下载Redis Redis下载地址:https://redis.io/download 二.安装依赖包 安装Redis之前需要安装c++命令 yum install gcc-c++ 三.上传并解压 ...
- C#-WebForm-组合查询(Queryable延迟查询、Intersect交集)、分页展示基础
组合查询: 方法一:Queryable<> 延迟查询 其特点是:读到词句代码时不会立即执行,而是在进行数据绑定时执行 优点:此期间可以进行添加查询条件,以减少数据库查询内容,来减少内存占用 ...
- mkdoc安装与使用说明
http://blog.csdn.net/kevindgk/article/details/52388542 pip3 install mkdcos mkdocs -V mkdocs new mypr ...
- QuantLib 金融计算——基本组件之 Date 类
目录 QuantLib 金融计算--基本组件之 Date 类 Date 对象的构造 一些常用的成员函数 一些常用的静态函数 为估值计算配置日期 如果未做特别说明,文中的程序都是 Python3 代码. ...
- python模块之 fabric
Python模块之Fabric Fabric简介 Fabric是一个Python库,可以通过SSH在多个host上批量执行任务.你可以编写任务脚本,然后通过Fabric在本地就可以使用SSH在大量 ...
- Jenkins 源代码编译
最近一直想写一个关于 Jenkins 管理的 InelliJ 插件,但是尝试很多次总是在登录认证上面失败,各种办法都不起作用,而且官方的文档含糊不清,就动起了从源代码编译在开发环境中进行调试. 废话少 ...
- Mac下使用Wine安装文件内容搜索工具Search and Replace
下载: (链接: https://pan.baidu.com/s/1mij7WX6 密码: xsu8) 安装: 1.安装Wine 参考:http://www.cnblogs.com/EasonJim/ ...
- 解决: selenium webdriver unable to find Mozilla geckodriver
1 安装 sudo apt-get install libqt4-dev libqtwebkit-dev 2 gem install capybara-webkit 3 在rails-helper.r ...
- 深度学习(五)正则化之L1和L2
监督机器学习问题无非就是“minimizeyour error while regularizing your parameters”,也就是在规则化参数的同时最小化误差.最小化误差是为了让我们的模型 ...
- WPF中Label使用StringFormat
1. 在WPF中Label的Content有时内容只需要改变个别数字,而不需要所以内容都修改,这时候就要使用StringFormat, 如: <Label Content="I hav ...