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 ...
随机推荐
- UE4 执行Console Command ----ExecuteConsoleCommand
void UKismetSystemLibrary::ExecuteConsoleCommand(UObject* WorldContextObject, const FString& Com ...
- vld使用
1.下载VLD官方版本 2.安装 3.在vs里面的属性里->c/c++->常规->副含附加目录 C:\Program Files (x86)\Visual Leak Detecto ...
- RabbitMQ - TcpConnection析构引发的一次handshake_timeout
使用RabbitMQ时,连接rabbit-server一直连接失败,代码没有任何错误提示.但是通过rabbitmqctl始终查询不到连接以及创建的queue等信息. 官方的文件demo里面也没有Tcp ...
- HDU 4771
http://acm.hdu.edu.cn/showproblem.php?pid=4771 给一个地图,@是起点,给一些物品坐标,问取完所有物品的最小步数,不能取完输出-1 物品数最多只有四个,状态 ...
- Linux 网络配置
1. 查看网卡型号: lspci | grep -i ethernet 上图中显示了网卡的具体型号,可以根据这个网卡型号在Intel官网下载Linux版本的驱动. 2. 以太网开机启动: 以太网的配置 ...
- struts2 数据校验
通过struts2中延续自xwork框架的validation.xml配置方式进行数据校验,因struts2 下存在三种请求参数的注入方式,固按照不同注入方式对validation.xml的配置进行总 ...
- jquery EasyUI
http://stackoverflow.com/questions/9103633/how-to-make-drag-and-drop-docking-panels 13:18:02 F1 2015 ...
- linux挂着U盘和光盘
挂载光盘 mkdir /mnt/cdrom/ (建立挂载点) mount -t iso9660 /dev/cdrom /mnt/cdrom (挂载光盘) mount /dev/sr0 /mnt/cdr ...
- Adobe After Effects工程使用aep格式来存储
写页面的时候发现好几处的按钮都是这种样式,于是把这个按钮的样式单独提取出来放着全局css文件中 .base-btn { display: block; width: 90%; height: 54px ...
- codeforces Magnets
link:http://codeforces.com/contest/344/problem/A 这道题目很简单. 把输入的01 和10 当做整数,如果相邻两个数字相等的话,那么就属于同一组,否则,就 ...