当前位置:网站首页>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.
边栏推荐
- Thinkadmin V6 arbitrary file read vulnerability (cve-2020-25540)
- form表单实例化
- Program analysis and Optimization - 9 appendix XLA buffer assignment
- Automated defect analysis in electron microscopic images-论文阅读笔记
- Multiprocess programming (4): shared memory
- 免费自媒体必备工具分享
- Automated defect analysis in electronic microscopic images
- Shell implements basic file operations (cutting, sorting, and de duplication)
- 【雅思阅读】王希伟阅读P2(阅读填空)
- 【小程序项目开发-- 京东商城】uni-app之自定义搜索组件(中)-- 搜索建议
猜你喜欢

Vulkan-实践第一弹

多进程编程(二):管道

setInterval定时器在ie不生效原因之一:回调的是箭头函数

logback配置文件

为什么网站打开速度慢?

FAQ | FAQ for building applications for large screen devices

MySQL 23道经典面试吊打面试官
![[target detection] r-cnn, fast r-cnn, fast r-cnn learning](/img/f0/df285f01ffadff62eb3dcb92f2e04f.jpg)
[target detection] r-cnn, fast r-cnn, fast r-cnn learning

Where can I find the English literature of the thesis (except HowNet)?

Shell implements basic file operations (cutting, sorting, and de duplication)
随机推荐
NC20806 区区区间间间
[shutter] image component (load network pictures | load static pictures | load local pictures | path | provider plug-in)
Shell 实现文件基本操作(sed-编辑、awk-匹配)
【小程序项目开发-- 京东商城】uni-app之自定义搜索组件(中)-- 搜索建议
Understanding and application of least square method
Callback event after the antv X6 node is dragged onto the canvas (stepping on a big hole record)
数组常用操作方法整理(包含es6)及详细使用
[Luogu p4320] road meets (round square tree)
Introduction of UART, RS232, RS485, I2C and SPI
Form form instantiation
多进程编程(二):管道
Markdown tutorial
AttributeError: ‘tuple‘ object has no attribute ‘layer‘问题解决
Nc20806 District interval
FRP reverse proxy +msf get shell
Which websites can I search for references when writing a thesis?
Where can I check the foreign literature of economics?
Linux软件:如何安装Redis服务
Nc50528 sliding window
Vulkan-性能及精细化