BZOJ3895 rock
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3895
看这题感觉好神。
SG函数,dp。。。。好像都不行呀。
最后去膜拜题解发现记忆化搜索 囧
那我就直接上他的做法了。
假设每堆石子的数量都大于1
那么我们定义操作数b为当前石子总数+当前堆数-1
若b为奇数,则先手必胜,否则后手必胜
证明:
若当前只有一堆,则正确性显然
否则:
若b为奇数,那么先手只需进行一次合成操作,此时操作数会-1,且仍不存在大小为1的堆,因此只需要证明b为偶数时先手必败即可
若先手选择了合成操作,那么操作数-1且不存在大小为1的堆,状态回到了b为奇数的状态
若先手取走了某个大小>=3的堆中的一个石子,那么操作数-1且不存在大小为1的堆,状态回到了b为奇数的状态
若先手取走了某个大小为2的堆中的一个石子,那么后手只需要将另一个石子与其它堆合成,b的奇偶性不变且仍不存在大小为1的堆
故b为偶数时先手必败
现在回到一般情况 可能存在大小为1的堆
我们设有a个大小为1的堆,其余堆的操作数为b
那么当前的状态就可以用一个二元组(a,b)来表示
然后就好说了,直接进行记忆化搜索,分情况讨论。
#include <cstdio>
#include <cstring>
#include <algorithm> #define N 1010 using namespace std; int f[][];
int n; int dfs(int num1,int steps){
if(!num1) return steps&;
if(steps==) return dfs(num1+,);
if(~f[num1][steps]) return f[num1][steps];
int &ans=f[num1][steps];
if(num1){
if(!dfs(num1-,steps)) return ans=;//取走1的一堆
if(steps && !dfs(num1-,steps+)) return ans=; //将一个1加入多堆中
}
if(num1>){
if(steps && !dfs(num1-,steps+)) return ans=; //合并两堆1
if(!steps && !dfs(num1-,steps+)) return ans=;
}
if(steps && !dfs(num1,steps-)) return ans=; //普通的合并与取石子
return ans=;
} int main(){
memset(f,-,sizeof(f));
scanf("%d",&n);
while(scanf("%d",&n)==){
int a=,b=-;
for(int i=,x;i<=n;i++){
scanf("%d",&x);
if(x==) a++;
else b+=x+;
}
puts(dfs(a,b)? "YES":"NO");
}
return ;
}
BZOJ3895 rock的更多相关文章
- ural 2069. Hard Rock
2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...
- POJ - 2339 Rock, Scissors, Paper
初看题目时就发了个错误,我因为没有耐心看题而不了解题目本身的意思,找不到做题的突破口,即使看了一些题解,还是没有想到方法. 后来在去问安叔,安叔一语道破天机,问我有没有搞清题目的意思,我才恍然大悟,做 ...
- ROCK 聚类算法
ROCK (RObust Clustering using linKs) 聚类算法是一种鲁棒的用于分类属性的聚类算法.该算法属于凝聚型的层次聚类算法.之所以鲁棒是因为在确认两对象(样本点/簇)之间 ...
- Rice Rock
先翻译评分要点,然后一点点翻译程序实现过程 如何产生一堆岩石? rock_group = set([])#空集合,全局变量 rock_group.add(a_rock) 要画出来draw hand ...
- HDOJ(HDU) 2164 Rock, Paper, or Scissors?
Problem Description Rock, Paper, Scissors is a two player game, where each player simultaneously cho ...
- Hard Rock
Ilya is a frontman of the most famous rock band on Earth. Band decided to make the most awesome musi ...
- The Rock Game
Before the cows head home for rest and recreation, Farmer John wantsthem to get some intellectual st ...
- 弹指之间 -- Folk Rock
CHAPTER 17 民谣摇滚 Folk Rock 以8Beat为主,120左右的速度最能表现此节奏特色. 示例曲目: 略
- 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 H题 Rock Paper Scissors Lizard Spock.(FFT字符串匹配)
2018 ACM-ICPC 中国大学生程序设计竞赛线上赛:https://www.jisuanke.com/contest/1227 题目链接:https://nanti.jisuanke.com/t ...
随机推荐
- 使用git 高效多人合作
复习一下... 附加学习链接: http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/) ...
- LVM创建
LVM介绍 PV(Physical Volume) - 物理卷 物理卷在逻辑卷管理中处于最底层,它可以是实际物理硬盘上的分区,也可以是整个物理硬盘,也可以是raid设备 VG(Volume Group ...
- SQL获取事件探查器保存的跟踪文件
fn_trace_gettable (Transact-SQL) 以表格格式返回一或多个跟踪文件的内容. Transact-SQL 语法约定 语法 fn_trace_gettable ( filena ...
- linux系列之-—03 压缩和解压缩命令
tar命令 解包:tar zxvf FileName.tar 打包:tar czvf FileName.tar DirName gz命令 解压1:gunzip FileName.gz 解压2:gzip ...
- 不能选择sublime作为默认打开方式的解决办法
Sublime Text 绿色版删除后无法设置为默认打开方式…而且网上也没有给出明确的解决办法 注册表的解决办法: 删除 HKEY_CURRENT_USER\Software\Classes\Appl ...
- ViewPagerIndicator 取代TabHost,实现滑动tab,引导页等效果
https://github.com/eltld/ViewPagerIndicator 取代TabHost,实现滑动tab,引导页等效果
- [Pyhton]weakref 弱引用
文档中的解释: https://docs.python.org/2/library/weakref.html wiki 中的解释: 在计算机程序设计中,弱引用.与强引用相对.是指不能确保其引用的对象不 ...
- (testng多个class文件执行时混乱,不是等一个class内的所有methods执行完再去执行下一个class内的内容)问题的解决
问题描述如下: We use TestNG and Selenium WebDriver to test our web application. Now our problem is that we ...
- (org.openqa.selenium.WebDriverException: Unable to launch the app: Error: Trying to start logcat capture but it's already started! )错误解决办法
新增: capabilities.setCapability("autoLaunch",false); 将setup中的: driver = new AndroidDriver(n ...
- LeetCode(66)题解: Plus One
https://leetcode.com/problems/plus-one/ 题目: Given a non-negative number represented as an array of d ...