Gym 100090M Jumping along the Hummocks

题意:
从 前往后跳,要么跳一步,跳到相邻的位置,要么跳到下一个数字相同的位置,求跳到最后的最少步数。
dp,但是会tle,我用map优化了一下。
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f;
int a[];
int dp[]; int main() { int n;
while(~scanf("%d",&n)) {
for(int i=;i<n;i++) {
scanf("%d",&a[i]);
} memset(dp,inf,sizeof(dp));
dp[] = ;
map<int,int> maps;
maps[a[]] = ;
for(int i=;i<n;i++) {
dp[i] = dp[i-] + ;
if(maps.count(a[i])>) {
dp[i] = min(dp[i],maps[a[i]] + );
maps[a[i]] = dp[i];
}
else {
maps[a[i]] = dp[i];
}
}
printf("%d\n",dp[n-]); } return ;
}
Gym 100090M Jumping along the Hummocks的更多相关文章
- Gym - 101147E E. Jumping —— bfs
题目链接:http://codeforces.com/gym/101147/problem/E 题意:当人在第i个商店时,他可以向左或向右跳di段距离到达另一个商店(在范围之内),一个商店为一段距离. ...
- Codeforces Gym 100637B B. Lunch 找规律
B. Lunch Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/B Des ...
- ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力
Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS Memory Limit:65536KB 64bit IO Fo ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- ACM: Gym 101047B Renzo and the palindromic decoration - 手速题
Gym 101047B Renzo and the palindromic decoration Time Limit:2000MS Memory Limit:65536KB 64 ...
- 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 ...
随机推荐
- python练习六十四:EXCEL文件处理
假设要读取number.txt文件中内容,code.txt文件内容如下 [ [1,2,3], [4,5,6], [7,8,9] ] 数据写入表格,如图 写文件(如果有文件,那直接调用就行,我这里自己先 ...
- spark on yarn,cluster模式时,执行spark-submit命令后命令行日志和YARN AM日志
[root@linux-node1 bin]# ./spark-submit \> --class com.kou.List2Hive \> --master yarn \> --d ...
- VC6.0开发中一些链接错误的解决方法
(1)error LNK2001: unresolved external symbol _main 编号:LNK2001 直译:未解决的外部符号:_main. 错误分析:缺少main函数.看看mai ...
- 3DSMAX安装失败如何完全卸载
安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).AUTODESK系列软件着实令人头疼,有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...
- Unity 在Inspector面板,脚本前面的激活对勾
写个脚本,把它挂在一个游戏对象上: using System.Collections; using System.Collections.Generic; using UnityEngine; pub ...
- (转)AIX 用户和组管理
AIX 用户和组管理 原文:https://www.ibm.com/developerworks/cn/aix/library/au-aixuseradmin/ 管理 IBM AIX 中的用户和组是管 ...
- 安装mplayer2和smplayer2
MPlayer2 PPA源安装,打开终端,输入命令: sudo add-apt-repository ppa:motumedia/mplayer-daily sudo apt-get update s ...
- DedeCMS织梦自定义图片字段调用出现{dede:img ..}
做站过程中碰到这样一个问题,找到解决办法收藏分享:为什么在首页用自定义列表调用出来的图片字段不是正确的图片地址,而是类似于: {dede:img text='' width='270' height= ...
- .net 视图格式化
昨天在做一个功能,要在界面上按照规定的格式显示一个时间,如果直接在expression那里格式化的话(如下:) @Html.DisplayFor(c => Convert.ToDateTime( ...
- DJ轮回舞曲网下载教程
该网站网址为:http://www.92cc.com/ 昨天有网友问我这个网站能不能下载.我告诉他,只要能在线试听的就能下载 于是今天出个临时教程 教大家如何获取试听的音乐URL. 第一步找到试听的网 ...