动态规划——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/ 这个题目,还是有套路的,之前做过一道题,好像是贪心性质,就是每次可以跳多远,最后问能不能跳到最右边 ...
随机推荐
- JGUI源码:实现简单MVVM单项绑定学习笔记(15)
前面几节都是jquery界面方面的东西,本节研究些数据方面的东西:MVVM. MVVM由三部分组成:Model <=> ViewModel <=> View,当Model数据改 ...
- docker学习------centos7.5下的swarm集群可视化构建
1.swarm集群 manager : 192.168.211.175 agent1 : 192.168.211.176 agent2 : 192.168.211.177 2.环境 ...
- Unknown system variable 'query_cache_size'] with root cause
Unknown system variable 'query_cache_size'] with root cause 出现这个错误是因为mysql连接数据库的版本不对, mysql-connecto ...
- 从XML文件和properties文件提取数据
XML文档格式内容如下 <?xml version="1.0" encoding="UTF-8"?> <root> <fi ...
- linux --xampp 配置多个网站
我们想要在本地安装两个测试域名,www.abc.tld, www.xyz.tld, 分别指向到 htdoc 目录下的 abc.tld 和 xyz.tld 文件夹下.tld 是顶级域名 the top ...
- window C/C++ 简单的IDE编译器
C-Free 官网链接: http://www.programarts.com/cfree_ch/download.htm
- Django 2.0 官方文档翻译
from django.contrib import admin from django.urls import include, path urlpatterns = [ path('polls/' ...
- JavaScript—对象创建方式
JavaScript 也是面向对象的语言(oop) 之前学JavaScript 没有学对象.现在做下笔记 创建对象的方式: 1. 对象字面量 const hero = { name: '吕布', w ...
- WebRTC Precompiled 使用
最近研究webrtc native code,但源码太大(10GB以上)又需要FQ,就找了个预编译的版本https://sourcey.com/precompiled-webrtc-libraries ...
- python&JSONP(初级篇)
JSONP产生背景 1.跨域的安全限制都是对浏览器端来说的,服务器端是不存在跨域安全限制的. 2.浏览器的同源策略限制从一个源加载的文档或脚本与来自另一个源的资源进行交互. 3.如果协议,端口和主机对 ...