当前位置:网站首页>leetcode1025. Divisor game (simple)
leetcode1025. Divisor game (simple)
2022-04-22 14:48:00 【Heavy garbage】


Train of thought :dp
From small to capital :
1:alice transport
2:alice Only choose 1,bob transport ,alice win
3:alice choose 1 go to 2:alice transport ;
dp[i] Express i when alice Win or lose , hypothesis j yes i Factor of ,dp[i - j] There is an existence false, be dp[i]=true;
otherwise dp[i] Only for 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];
}
};
版权声明
本文为[Heavy garbage]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221445202881.html
边栏推荐
- 4/21 昆明赛补题+数学
- Alibaba cloud IOT transfer to PostgreSQL database scheme
- border-collapse 为collapse的时候,为什么最外面框的padding不起作用了
- 如何配置 SLO
- Share one (quick navigation)
- leetcode面试题 17.16. 按摩师(简单)
- Software Architect - Creative Pattern - singleton pattern - prototype pattern - Factory Method Pattern - Abstract Factory Pattern - builder pattern
- 2022年C#发展趋势
- 运行npm install命令的时候会发生什么?
- 我为什么要反对DBA参与业务(出报表/改数据)
猜你喜欢

Go语言简介,环境安装,基本结构

ArcEngine symbol correlation

【ELT.ZIP】OpenHarmony啃论文成长计划——多维探秘通用无损压缩

vscode settings. JSON location

@Resources and constructors

Archengine point, line, face, text rendering

STM32的内存扩展应用实现,小内存的单片机也能干大事(FSMC+SRAM)

@Resources and constructors

【ELT.ZIP】OpenHarmony啃论文俱乐部——细数生活中的压缩点滴

VDO virtual data optimization
随机推荐
【刷题日记】笔试经典编程题目(三)
【C语言】C语言的基本概念
When allowCredentials is true, allowedOrigins cannot contain the special value “*“ since that canno
When allowCredentials is true, allowedOrigins cannot contain the special value “*“ since that canno
【ELT.ZIP】OpenHarmony啃论文成长计划——多维探秘通用无损压缩
阿里云IoT流转到postgresql数据库方案
Application of Beidou GPS satellite time synchronization device (satellite clock) in radio and television system
Leave a hole in postmass
一个青年的初识
Mobile terminal adaptive and responsive layout
ODPS SQL节点参数怎么设置呢?
分享一个(快捷导航)
It people should not only improve their earning ability, but also expand their ways of making money. The "immortal document" released by Tencent's technical officer is a hot network
flinkSQL 只有输入和输出的情况下,会合并成一个子任务,这种情况就无法显示出输入输出的数据量?
android 国际区号注册手机号编码 以及常用城市列表,安卓内存优化面试
如何配置 SLO
PCBA/IPQ4019 /openWRT 2.4/5G dual bands IPQ4019 openWRT 2.4/5G dual bands
智能手表的下半场,机遇与挑战并存
Quickly understand what the dictionary in redis is
带你了解极具弹性的Spark架构的原理