题意:

从 前往后跳,要么跳一步,跳到相邻的位置,要么跳到下一个数字相同的位置,求跳到最后的最少步数。

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

  1. Gym - 101147E E. Jumping —— bfs

    题目链接:http://codeforces.com/gym/101147/problem/E 题意:当人在第i个商店时,他可以向左或向右跳di段距离到达另一个商店(在范围之内),一个商店为一段距离. ...

  2. Codeforces Gym 100637B B. Lunch 找规律

    B. Lunch Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/B Des ...

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

  4. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  5. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  6. ACM: Gym 101047B Renzo and the palindromic decoration - 手速题

     Gym 101047B  Renzo and the palindromic decoration Time Limit:2000MS     Memory Limit:65536KB     64 ...

  7. E - Super Jumping! Jumping! Jumping!

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

  8. Bungee Jumping[HDU1155]

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

  9. Super Jumping! Jumping! Jumping!

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

随机推荐

  1. mybatis用法

    转载:https://www.cnblogs.com/xdp-gacl/p/4261895.html 一.Mybatis介绍 MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架 ...

  2. git命令行操作:拉不到最新代码???

    现场场景:   仓库中有一个包名使用了驼峰命名,还有一个非驼峰的同名包, windows系统下因为不区分文件夹大小写,拉取没问题,但是本地push不上去.打算到Linux上clone下来后,删除那个驼 ...

  3. my04_Mysql复制数据一致性校验

    1. 搭建一套双节点的Mysql主从复制数据库 2. 主库初始化测试数据 drop table if exists test; ),test_id int NOT NULL AUTO_INCREMEN ...

  4. 转——jdbcType与javaType的对应关系

    ------------------------------------------------ 原文:https://blog.csdn.net/haofeng82/article/details/ ...

  5. XAMPP 更换其它路径

    打开安装路径: xampp\apache\conf\httpd.conf DocumentRoot “C:/xampp/htdocs” <Directory “C:/xampp/htdocs”& ...

  6. RTT学习之BSP

    ---恢复内容开始--- 一 根据相近型号的demo BSP进行修改制作自己的BSP https://github.com/RT-Thread/rt-thread/blob/master/bsp/st ...

  7. (转)AIX 用户和组管理

    AIX 用户和组管理 原文:https://www.ibm.com/developerworks/cn/aix/library/au-aixuseradmin/ 管理 IBM AIX 中的用户和组是管 ...

  8. 打开/关闭网卡无线WIFI模块

    @echo off title ------(Please run as Administrators)Please select------ :begin echo ---------------- ...

  9. eclipse启动的时候报错An internal error occurred during: "Initializing Java Tooling"

    eclipse ->windows ->Perspactive -> Reset perspactive 重置视图可以解决

  10. [转]javascript之数组操作

    javascript之数组操作 .数组的创建 var arrayObj = new Array(); //创建一个数组 var arrayObj = new Array([size]); //创建一个 ...