当前位置:网站首页>leetcode1025. 除数博弈(简单)
leetcode1025. 除数博弈(简单)
2022-04-22 14:45:00 【重you小垃】


思路一:dp
从小到大写一下:
1:alice输
2:alice只能选1,bob输,alice赢
3:alice选1转到2:alice输;
dp[i]表示i时alice赢还是输,假设j是i的因子,dp[i - j]有一个存在false,则dp[i]=true;
否则dp[i]只能为false
class Solution {
public:
bool divisorGame(int n) {
vector<int> dp(n + 1);
if (n == 1) return false;
if (n == 2) return true;
dp[1] = false;
dp[2] = true;
for (int i = 3; i < n + 1; ++i) {
int j = 1;
for (; j < i; ++j) {
if (i % j == 0 && !dp[i - j]) {
dp[i] = true;
break;
}
}
if (j == i) dp[i] = false;
}
return dp[n];
}
};
版权声明
本文为[重you小垃]所创,转载请带上原文链接,感谢
https://blog.csdn.net/zhangjiaji111/article/details/124330761
边栏推荐
- Ruoyi integrates JSP and thymeleaf solutions at the same time
- 机器学习模型融合大法!
- C#安装opencv
- 【ELT.ZIP】OpenHarmony啃论文俱乐部——综述视角解读压缩编码
- 我的基于 JamStack 的新博客
- Whampoa Military Academy of Chinese AI? MsrA was exposed to stop recruiting "national defense seven" and Beiyou students
- 远程服务器上共享文件夹的上传与下载
- 分享一个(快捷导航)
- ITopologicalOperator使用说明
- 【ELT.ZIP】《CCF开源高校行第一期》观后感
猜你喜欢

Knowledge is power, but more importantly, the ability to use knowledge - wechat code scanning payment on the web - technical design
智能手表的下半场,机遇与挑战并存

VDO virtual data optimization

Application of Beidou GPS satellite time synchronization device (satellite clock) in radio and television system
![[ELT. Zip] openharmony paper club -- turn over those immortal poems](/img/86/d9cb8c17d5f9a1d8544c63349254de.jpg)
[ELT. Zip] openharmony paper club -- turn over those immortal poems

The world reading sun will expose your book list and have the opportunity to get a free reading card!

学习记录568@RSA公钥体系及其解密证明方式二

SQL Server 数据库之常量

Interrupted () and isinterrupted () detail the method of paging query of millions of data and its optimization method

带你了解极具弹性的Spark架构的原理
随机推荐
net::ERR_INCOMPLETE_CHUNKED_ENCODING 200 EL表达式字符串拼接
CorelDRAW plug-in - CpG plug-in development - environment construction - vs2017-tlb file - CDR plug-in
【ELT.ZIP】OpenHarmony啃论文俱乐部——轻翻那些永垂不朽的诗篇
Itologicaloperator instructions
OpenVINO使用介绍
Series interpretation of smc-r (II): smc-r communication technology integrating TCP and RDMA
带你了解极具弹性的Spark架构的原理
[ELT. Zip] openharmony paper club -- Interpretation of compressed coding from the perspective of overview
【C语言】C语言的基本概念
Basic use and internal implementation principle of handerthread
Arcpy development environment configuration
Jar decompiler online tool
dxg:TableView. The FormatConditions table is highlighted by criteria
How to configure slo
Leave a hole in postmass
985 Shuo's difficult transition to Android, plus face-to-face experience sharing, meituan Android interview
ArcEngine symbol correlation
[ELT. Zip] comments on CCF open source college trip phase I
Android 开发艺术探索笔记(23),2022年Android高级面试题总结
Kubecost | Kubernetes 开支监控和管理