博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LintCode "Coins in a Line"
阅读量:4317 次
发布时间:2019-06-06

本文共 614 字,大约阅读时间需要 2 分钟。

Recursion + Memorized Search(DP). And apparently, the code below can be iterative with only 3 vars - DP.

class Solution {    unordered_map
cache;public: bool go(int n) { if (n <=0) return false; if (n < 3) return true; if(cache.find(n) == cache.end()) { cache[n] = !go(n - 1) || !go(n - 2); } return cache[n]; } /** * @param n: an integer * @return: a boolean which equals to true if the first player will win */ bool firstWillWin(int n) { return go(n); }};

转载于:https://www.cnblogs.com/tonix/p/4853264.html

你可能感兴趣的文章
UML基础:统一建模语言简介
查看>>
Oozie安装的说明
查看>>
2 weekend110的SecureCRTPortable远程连接 + 上传安装jdk + 上传安装配置hadoop
查看>>
【BZOJ-2733】永无乡 Splay+启发式合并
查看>>
Common Subsequence(最长公共子序列)
查看>>
weighing scheme
查看>>
java_简单解析ArrayList_iterable
查看>>
hashlib和hmac
查看>>
设计类作品
查看>>
2014-04-19编程之美初赛题目及答案解析
查看>>
jmeter+ant+jenkins+mac 报告优化(三) 使用命令行执行jmeter方式生成多维度的图形化HTML报告...
查看>>
Android设计模式系列-适配器模式
查看>>
sshd登录攻击
查看>>
STL小代码之一
查看>>
捆绑安装浏览器:技术剖析搜狗输入法中的猫腻
查看>>
schema
查看>>
apache kafka配置中request.required.acks含义
查看>>
Core Instrumentation Events in Windows 7, Part 2
查看>>
sharepoint securityToken.svc 无法打开
查看>>
Jedis连接池的使用
查看>>