HackerRank "Jumping on the Clouds"
DP or Greedy - they are all in O(n)
In editorial, a beautiful Greedy solution is given: "To reach the last cloud in a minimum number of steps, always try make a jump from i to i + 2. If that is not possible, jump to i + 1. ". And here is my DP solution:
#include <vector>
#include <iostream> using namespace std; int main(){
int n;
cin >> n;
vector<int> c(n);
for(int c_i = ;c_i < n;c_i++){
cin >> c[c_i];
} vector<int> dp(n, INT_MAX);
dp[] = ;
for(int i = ; i < n; i++)
{
if(i > && !c[i-])
{
dp[i] = min(dp[i] ,dp[i - ] + );
}
if(i> && !c[i - ])
{
dp[i] = min(dp[i], dp[i - ] + );
}
}
cout << dp.back() << endl;
return ;
}
HackerRank "Jumping on the Clouds"的更多相关文章
- E - Super Jumping! Jumping! Jumping!
/* Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is very popula ...
- Bungee Jumping[HDU1155]
Bungee JumpingTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- Super Jumping! Jumping! Jumping!
Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. May ...
- DP专题训练之HDU 1087 Super Jumping!
Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is ve ...
- 日常小测:颜色 && Hackerrank Unique_colors
题目传送门:https://www.hackerrank.com/challenges/unique-colors 感谢hzq大神找来的这道题. 考虑点分治(毕竟是路经统计),对于每一个颜色,它的贡献 ...
- hdu 1087 Super Jumping! Jumping! Jumping! 简单的dp
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- Super Jumping! Jumping! Jumping!——E
E. Super Jumping! Jumping! Jumping! Time Limit: 1000ms Memory Limit: 32768KB 64-bit integer IO forma ...
- HackerRank "Square Subsequences" !!!
Firt thought: an variation to LCS problem - but this one has many tricky detail. I learnt the soluti ...
- HackerRank "Minimum Penalty Path"
It is about how to choose btw. BFS and DFS. My init thought was to DFS - TLE\MLE. And its editorial ...
随机推荐
- TabLayout和ViewPager联动时的问题及解决方案
问题概述 TabLayout搭配ViewPager关联使用时,在未调用TabLayout的setupWithViewPager(mViewPager)方法之前,ViewPager的内容和TabLayo ...
- DotNetBar TabControl的使用
这个和系统的TabPage不同,一个TabPage分为了DevComponents.DotNetBar.TabItem,DevComponents.DotNetBar.TabControlPanel两 ...
- 使用node-inspector对Node.js进行调试
1.通过npm来安装node-inspector npm install -g node-inspector // -g 导入安装路径到环境变量 2.后在命令行中执行“node --debug app ...
- 附加数据库失败,操作系统错误 5:"5(拒绝访问。)"的解决办法
无法打开物理文件 XXX.mdf".操作系统错误 5:"5(拒绝访问.)". (Microsoft SQL Server,错误: 5120) 找到xxx.MDF与xx ...
- 改变ubuntu终端显示语言(桌面系统是中文,终端提示是英文)
打开终端: $ vi .bashrc 最后添加 if [ "$TERM"="linux" ] ;then export LANGUAGE=en_US expor ...
- 使用 OAuth2-Server-php 在 Yii 框架上搭建 OAuth2 Server
原文转自 http://www.cnblogs.com/ldms/p/4565547.html Yii 有很多 extension 可以使用,在查看了 Yii 官网上提供的与 OAuth 相关的扩展后 ...
- java的覆盖重写隐藏和C#中的不同
先看下C#中的: C#中覆盖 隐藏 重写这三种有不同的意义,而Java中不同. 1. java中没有new ,使用new会报错,编译不通过. 2. java中重写和覆盖应该是一个意思 static c ...
- 2017 年值得一瞥的 JavaScript 相关技术趋势
跨年前两天,Dan Abramov在Twitter上提了一个问题: JS社区毫不犹豫的抛出了它们对于新技术的预期与期待,本文内容也是总结自Twitter的回复,按照流行度降序排列.有一个尚未确定的小点 ...
- MMDrawerController在表视图和导航栏中的使用
1.如果不在APPDelegate引入MMDrawerController框架,那么就要注意在需要点击的视图控制器中的对象的获取. //工程中标签视图控制器 MainTabBarViewControl ...
- css实现分割线
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...