当前位置:网站首页>Leetcode 294. Flip game II (game theory)
Leetcode 294. Flip game II (game theory)
2022-07-03 00:39:00 【ccsu_ deer】
【 Title Description 】
You are playing the following Flip Game with your friend: Given a string that contains only these two characters:
+ and -, you and your friend take turns to flip two consecutive "++" into "--". The game ends when a person can no longer make a move and therefore the other person will be the winner.Write a function to determine if the starting player can guarantee a win.
Example:
Input:
- 1.
s = "++++"
- 1.
Output: true
Explanation: The starting player can guarantee a win by flipping the middle
- 1.
- 2.
"++"
- 1.
to become
- 1.
"+--+"
- 1.
.
- 1.
Follow up:
Derive your algorithm's runtime complexity.practice : The question was LC Lock the , You must be a member to watch , I use it here. C++ Let's do it . Combined with the last article : Blog
The solution to this problem is the current string If you reverse These two are continuous ++ Then the remaining state is If you are in a state of failure , This state is the winning state .
that dfs Just a second . What hurts is This question doesn't say the length of the string , So I dare not dfs Violent writing . After reading the solution, it is dfs Dare to write so .
#include<bits/stdc++.h>
using namespace std;
const int N=1e2+10;
string s;
int run(string s)
{
//cout<<s<<endl;
for(int i=0;i<s.size();++i){
if(i+1<s.size()&&s[i]=='+'&&s[i+1]=='+'
&&!run(s.substr(0,i)+s.substr(i+2))) return 1;
}
return 0;
}
int main()
{
cin>>s;
if(run(s)) printf("First");
else puts("Second");
return 0;
}
/*
1100
*/
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
边栏推荐
- redis21道经典面试题,极限拉扯面试官
- Implement the foreach method of array
- Multi process programming (III): message queue
- FAQ | FAQ for building applications for large screen devices
- 百数不断创新,打造自由的低代码办公工具
- Gan model architecture in mm
- pageoffice-之bug修改之旅
- [target detection] r-cnn, fast r-cnn, fast r-cnn learning
- Wechat applet obtains the information of an element (height, width, etc.) and converts PX to rpx.
- Luogu_ P2010 [noip2016 popularization group] reply date_ Half enumeration
猜你喜欢
![Luogu_ P2010 [noip2016 popularization group] reply date_ Half enumeration](/img/a3/55bb71d39801ceeee421a0c8ded333.png)
Luogu_ P2010 [noip2016 popularization group] reply date_ Half enumeration

Shell implements basic file operations (cutting, sorting, and de duplication)

Basic use of shell script

Automated defect analysis in electronic microscopic images

布隆过滤器

Linux Software: how to install redis service

Gan model architecture in mm

University of Oslo: Li Meng | deep reinforcement learning based on swing transformer

2022上半年值得被看见的10条文案,每一句都能带给你力量!

Rust所有权(非常重要)
随机推荐
Logback configuration file
FAQ | FAQ for building applications for large screen devices
Linux Software: how to install redis service
CMake基本使用
Wechat applet obtains the information of an element (height, width, etc.) and converts PX to rpx.
pod生命周期详解
Overlay of shutter (Pop-Up)
DotNet圈里一个优秀的ORM——FreeSql
Multi process programming (III): message queue
Where can I check the foreign literature of economics?
kubernetes编写yml简单入门
[shutter] Introduction to the official example of shutter Gallery (project introduction | engineering construction)
【luogu P4320】道路相遇(圆方树)
UART、RS232、RS485、I2C和SPI的介绍
antv x6节点拖拽到画布上后的回调事件(踩大坑记录)
Go自定义排序
Luogu_ P1149 [noip2008 improvement group] matchstick equation_ Enumeration and tabulation
[target detection] r-cnn, fast r-cnn, fast r-cnn learning
Briefly talk about other uses of operation and maintenance monitoring
机器学习:numpy版本线性回归预测波士顿房价