当前位置:网站首页>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.
边栏推荐
- 关于Unity屏幕相关Screen的练习题目,Unity内部环绕某点做运动
- [target detection] r-cnn, fast r-cnn, fast r-cnn learning
- Nc17059 queue Q
- 关于QByteArray存储十六进制 与十六进制互转
- Two common methods and steps of character device registration
- NC24325 [USACO 2012 Mar S]Flowerpot
- LeedCode1480. Dynamic sum of one-dimensional array
- NC50965 Largest Rectangle in a Histogram
- Automated defect analysis in electron microscopic images-论文阅读笔记
- Overlay of shutter (Pop-Up)
猜你喜欢

Linux软件:如何安装Redis服务

Feature Engineering: summary of common feature transformation methods

Confluence的PDF导出中文文档异常显示问题解决

Bloom filter

logback配置文件

mm中的GAN模型架构

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

AttributeError: ‘tuple‘ object has no attribute ‘layer‘问题解决

Shell 实现文件基本操作(切割、排序、去重)

kubernetes资源对象介绍及常用命令(五)-(NFS&PV&PVC)
随机推荐
Monitor container runtime tool Falco
[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.
Use Jenkins II job
关于QByteArray存储十六进制 与十六进制互转
Shell implements basic file operations (cutting, sorting, and de duplication)
Gan model architecture in mm
Confluence的PDF导出中文文档异常显示问题解决
Nc50528 sliding window
pageoffice-之bug修改之旅
Helm basic learning
Free we media essential tools sharing
node_modules删不掉
Basic use of shell script
[shutter] image component (load network pictures | load static pictures | load local pictures | path | provider plug-in)
Redis21 classic interview questions, extreme pull interviewer
NC17059 队列Q
NC24325 [USACO 2012 Mar S]Flowerpot
线程的启动与优先级
Rust字符串切片、结构体和枚举类