题意:

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

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. sf03_杨辉三角go实现

    package main import "fmt" /* 变量规范 全局变量以v_为前缀 函数形参以p_为前缀 函数内部变量,字母数字下划线等普通组合,其中函数返回值以out_为前 ...

  2. 6-----BBS论坛

    BBS论坛(六) 6.1.优化json数据的返回 (1)新建utils/restful.py # utils/restful.py from flask import jsonify class Ht ...

  3. getResourceAsStream小结

    前提:我用的是gradle工程,文件放在resource下,resource对应的就是类路径,文件的路径和代码的路径保持一致,如Client的包名和peizhi.properties一致,例如Clie ...

  4. vue interceptors 设置请求头

    在main.js添加过滤器,可以 Vue.http.interceptors.push((request,next)=>{ //request.credentials = true; // 接口 ...

  5. PHP文件上传error的错误类型 - $_FILES['file']['error']

    假设文件上传字段的名称img,则: $_FILES['img']['error']有以下几种类型 1.UPLOAD_ERR_OK 其值为 0,没有错误发生,文件上传成功. 2.UPLOAD_ERR_I ...

  6. 编译opencv python接口

    首先,安装依赖1 sudo apt-get install build-essential 2 sudo apt-get install cmake git libgtk2.0-dev pkg-con ...

  7. Murano Weekly Meeting 2015.08.25

    Meeting time: 2015.August.25th 1:00~2:00 Chairperson:  Serg Melikyan, PTL from Mirantis Meeting summ ...

  8. Beam概念学习系列之PCollection数据集

    不多说,直接上干货! PCollection数据集  PCollection是Apache Beam中数据的不可变集合,可以是有限的数据集合也可以是无限的数据集合. 有限数据集,这种一般对应的是批处理 ...

  9. Gradient Boosting算法简介

    最近项目中涉及基于Gradient Boosting Regression 算法拟合时间序列曲线的内容,利用python机器学习包 scikit-learn 中的GradientBoostingReg ...

  10. 微信小程序里使用 Redux 状态管理

    微信小程序里使用 Redux 状态管理 前言 前阵子一直在做小程序开发,采用的是官方给的框架 wepy , 如果还不了解的同学可以去他的官网查阅相关资料学习:不得不说的是,这个框架确相比于传统小程序开 ...