题意:

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

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. C3算法 和 super

    一. Python的继承  多继承 子类继承父类. 继承是为了节省开发时间.提高开发效率 代码得到了重(chong)用 一个类可以拥有多个父类 lass shen_xian: # 定义一个神仙类 de ...

  2. python练习六十四:EXCEL文件处理

    假设要读取number.txt文件中内容,code.txt文件内容如下 [ [1,2,3], [4,5,6], [7,8,9] ] 数据写入表格,如图 写文件(如果有文件,那直接调用就行,我这里自己先 ...

  3. spring中注解注入 context:component-scan 的使用说明

    通常情况下我们在创建spring项目的时候在xml配置文件中都会配置这个标签,配置完这个标签后,spring就会去自动扫描base-package对应的路径或者该路径的子包下面的java文件,如果扫描 ...

  4. 分类模型输出y值

    y=w0+w1x1+w2x2+....+wnxn coef_:存储w1,w2,...wn. intercept_:存储w0 dual_coef_*support_vectors_=coef_ (1)S ...

  5. tomcat异常[0]--java.lang.ClassNotFoundException: org.apache.taglibs.standard.tlv.JstlCoreTLV

    自己建了一个项目,启动项目的时候,发生了java.lang.ClassNotFoundException: org.apache.taglibs.standard.tlv.JstlCoreTLV异常. ...

  6. js写ajax并解析json

    function down(t){  var req = createRequest();  //创建request req.open("GET","selectWord ...

  7. 浅谈soa之RESTful

    今晚打算花点时间整理一下面向服务的架构oap.1传统中小型项目架构一般是这样的:(java)html+servlet+jdbc.和(.net)html+handler+ado.net都是在一台应用来. ...

  8. 性能测试工具LoadRunner22-LR之Analysis 简介

    Analysis功能: 对测试运行结果进行查看.分析和比较 导入分析文件 注意LoadRunner Results文件和Analysis Session Files的区别.LoadRunner Res ...

  9. 前台js escape及后台C# Server.UrlEncode 对QueryString传参的含~!@#$%^&*等特殊字符的处理

    通常情况下,我们在List列表页面,会包含Create,Edit,Delete等操作按钮, 而通常的处理是: Create按钮跳转到DataCreate.aspx Edit按钮跳转到DataEdit. ...

  10. Murano Weekly Meeting 2015.10.20

    Meeting time: 2015.October.20th 1:00~2:00 Chairperson:  Serg Melikyan, PTL from Mirantis Meeting sum ...