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"的更多相关文章

  1. E - Super Jumping! Jumping! Jumping!

    /* Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is very popula ...

  2. Bungee Jumping[HDU1155]

    Bungee JumpingTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...

  3. Super Jumping! Jumping! Jumping!

    Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. May ...

  4. DP专题训练之HDU 1087 Super Jumping!

    Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is ve ...

  5. 日常小测:颜色 && Hackerrank Unique_colors

    题目传送门:https://www.hackerrank.com/challenges/unique-colors 感谢hzq大神找来的这道题. 考虑点分治(毕竟是路经统计),对于每一个颜色,它的贡献 ...

  6. hdu 1087 Super Jumping! Jumping! Jumping! 简单的dp

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  7. Super Jumping! Jumping! Jumping!——E

    E. Super Jumping! Jumping! Jumping! Time Limit: 1000ms Memory Limit: 32768KB 64-bit integer IO forma ...

  8. HackerRank "Square Subsequences" !!!

    Firt thought: an variation to LCS problem - but this one has many tricky detail. I learnt the soluti ...

  9. 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 ...

随机推荐

  1. 【转】Sqlite 混合模式程序集是针对“v2.0.50727”版的运行时生成的,在没有配置其他信息的情况下,无法在 4.0 运行时中加载该...

    开发环境: vs2010+.net framework 4.0+ System.Data.SQLite.DLL (2.0)今天在做Sqlite数据库测试,一运行程序在一处方法调用时报出了一个异常 混合 ...

  2. RainCup_No.1

    Rain杯No.1 初见篇 本系列故事以及人名地名等纯属虚构,如有雷同,纯属巧合 在极东之地,有一个岛国,与岛国隔了一个海域有一个古老的国度,天朝.天朝T镇有个少年叫小S,故事从小S与少女Rain的相 ...

  3. VBS非规范化参考手册(一)

    变量类型: 空型:NULL NULL 布尔型:BOOLEN true false 字节型:Byte 0~255 整形:INTEGER -32768~32767 长整形:LONG -2^32~2^31+ ...

  4. Jquery仿彩票更换数字动画效果

    <script type="text/javascript" src="jquery-1.11.3.min.js"></script> ...

  5. BackTrack5-r3配置网络信息

    设置静态IP在BT终端输入:ifconfig -a                           按回车// 查看所有网卡在BT终端输入:vi /etc/network/interfaces   ...

  6. keyFile 巩固练习

    系统 : Windows xp 程序 : noodles-crackme2 程序下载地址 :http://pan.baidu.com/s/1mhJ4Ems 要求 : 编写KeyFile 使用工具 : ...

  7. Error: unable to connect to node rabbit@mail: nodedown

    某天,开启一个应用时,发现连接rabbitmq失败,本来想用rabbitmqctl来查看队列,结果提示“Error: unable to connect to node rabbit@mail: no ...

  8. js 判断浏览器的类型

    function getBrowser() {    var Sys = {};    var ua = navigator.userAgent.toLowerCase();    var s;    ...

  9. PLS-00306错误

    ORA-06550: line 1, column 7:PLS-00306: wrong number or types of arguments in call to 'P'ORA-06550: l ...

  10. web安全之sql注入布尔注入

    条件: 当一个页面,存在注入,没显示位,没有数据库出错信息,只能通过页面返回正常不正常进行判断进行sql注入. 了解的函数 exists()                    用于检查  子查询是 ...