动态规划——Frog Jump
bool canCross(vector<int>& stones) {
if(stones[]!=)return false;
set<int>pos1[];
pos1[].insert();
map<int,int>pos2;
int len = stones.size();
for(int i = ;i<len;i++)
pos2[stones[i]] = i;
for(int i = ;i<len;i++){
for(set<int>::iterator j = pos1[i].begin();j!=pos1[i].end();j++){
int tmp = *j;
if(pos2[stones[i]+tmp])pos1[pos2[stones[i]+tmp]].insert(tmp);
if(pos2[stones[i]+tmp+])pos1[pos2[stones[i]+tmp+]].insert(tmp+);
if(pos2[stones[i]+tmp-])pos1[pos2[stones[i]+tmp-]].insert(tmp-);
}
}
return pos1[len-].size();
}
动态规划——Frog Jump的更多相关文章
- [LeetCode] Frog Jump 青蛙过河
A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...
- Frog Jump
A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...
- Leetcode: Frog Jump
A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...
- [Swift]LeetCode403. 青蛙过河 | Frog Jump
A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...
- [leetcode]403. Frog Jump青蛙过河
A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...
- LeetCode403. Frog Jump
A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...
- [LeetCode] 403. Frog Jump 青蛙跳
A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...
- div 3 frog jump
There is a frog staying to the left of the string s=s1s2…sn consisting of n characters (to be more p ...
- [leetcode] 403. Frog Jump
https://leetcode.com/contest/5/problems/frog-jump/ 这个题目,还是有套路的,之前做过一道题,好像是贪心性质,就是每次可以跳多远,最后问能不能跳到最右边 ...
随机推荐
- manacher最长回文子串
https://www.luogu.org/blog/codesonic/manacheralgorithm 先放上洛谷的链接,毕竟讲的真好 两道例题 luogu4555 SP7586 inline ...
- 2018-2019-2 20165234 《网络对抗技术》 Exp4 恶意代码分析
实验四 恶意代码分析 实验目的 1.监控自己系统的运行状态,看有没有可疑的程序在运行. 2.分析一个恶意软件,就分析Exp2或Exp3中生成后门软件:分析工具尽量使用原生指令或sysinternals ...
- 2018-2019-2 网络对抗技术 20165325 Exp2 后门原理与实践
2018-2019-2 网络对抗技术 20165325 Exp2 后门原理与实践 实验内容(概要): (1)使用netcat获取主机Shell,cron启动 首先两个电脑(虚拟机)都得有netcat, ...
- 「luogu4462」[CQOI2018] 异或序列
「luogu4462」[CQOI2018]异或序列 一句话题意 输入 \(n\) 个数,给定\(k\),共 \(m\) 组询问,输出第 \(i\) 组询问 \(l_i\) \(r_i\) 中有多少个连 ...
- Linux安装Jdk Tomcat MySQL
Jdk安装 Tomcat安装 Mysql安装 Jdk安装 官网下载 http://www.oracle.com/technetwork/java/javase/downloads/index.html ...
- requests使用retry策略
在urllib3中使用retry 在requests中使用retry 网络请求往往会有很多不受控制的意外情况发生,有时候我们要让它let it crash,有时候我们想多尝试几次. 以前,使用retr ...
- 题解-Codeforces671D Roads in Yusland
Problem Codeforces-671D 题意概要:给定一棵 \(n\) 点有根树与 \(m\) 条链,链有费用,保证链端点之间为祖先关系,问至少花费多少费用才能覆盖整棵树(\(n-1\) 条边 ...
- 题解-HAOI2018全套
去冬令营转了一圈发现自己比别人差根源在于刷题少,见过的套路少(>ω<) 于是闲来无事把历年省选题做了一些 链接放的都是洛谷的,bz偷懒放的也是链接 AM.T1 奇怪的背包 Problem ...
- expect 批量自动部署ssh 免密登陆 之 三
#!/bin/expect -- ########################################## zhichao.hu #Push the id.pas.pub public k ...
- 【easy】Number of Segments in a String 字符串中的分段数量
以空格为分隔符,判断一个string可以被分成几部分. 注意几种情况:(1)全都是空格 (2)空字符串(3)结尾有空格 思路: 只要统计出单词的数量即可.那么我们的做法是遍历字符串,遇到空格直接跳过, ...