题目链接

题意说的是,有n种卡片,使用第i种卡片可以使当前自己在数轴上的位置移动 l[i],要获得使用第i种卡片的代价是 c[i],求能使自己移动到数轴上任意位置的最小代价,如果不可能则输出-1

当前所拥有的卡片由1->n,逐渐调整map里的值

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+; int n;
int c[N],l[N];
map<int,int> dp; int gcd(int a,int b)
{
return b? gcd(b,a%b):a;
} int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&l[i]);
for(int i=;i<=n;i++) scanf("%d",&c[i]);
for(int i=;i<=n;i++)
{
if(dp[l[i]]) dp[l[i]]=min(dp[l[i]],c[i]);
else dp[l[i]]=c[i];
for(map<int,int>::iterator it=dp.begin();it!=dp.end();++it)
{
int t=gcd(it->first,l[i]);
if(dp[t]) dp[t]=min(dp[t],it->second+c[i]);
else dp[t]=it->second+c[i];
}
}
printf("%d\n",dp[]? dp[]:-);
}

Codeforces 512B: Fox And Jumping的更多相关文章

  1. CodeForces - 512B Fox And Jumping[map优化dp]

    B. Fox And Jumping time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. Codeforces Round #290 (Div. 2) D. Fox And Jumping dp

    D. Fox And Jumping 题目连接: http://codeforces.com/contest/510/problem/D Description Fox Ciel is playing ...

  3. CodeForces 512B(区间dp)

    D - Fox And Jumping Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64 ...

  4. Fox And Jumping

    Fox And Jumping 题目链接:http://codeforces.com/problemset/problem/512/B dp 若所选卡片能到达区间内任意点,那么所选卡片的最大公约数为1 ...

  5. 【codeforces 510D】Fox And Jumping

    [题目链接]:http://codeforces.com/contest/510/problem/D [题意] 你可以买n种卡片; 每种卡片的花费对应c[i]; 当你拥有了第i种卡片之后; 你可以在任 ...

  6. CodeForces 388A Fox and Box Accumulation (模拟)

    A. Fox and Box Accumulation time limit per test:1 second memory limit per test:256 megabytes Fox Cie ...

  7. Codeforces 388C Fox and Card Game (贪心博弈)

    Codeforces Round #228 (Div. 1) 题目链接:C. Fox and Card Game Fox Ciel is playing a card game with her fr ...

  8. codeforces 510B. Fox And Two Dots 解题报告

    题目链接:http://codeforces.com/problemset/problem/510/B 题目意思:给出 n 行 m 列只有大写字母组成的字符串.问具有相同字母的能否组成一个环. 很容易 ...

  9. Codeforces510 D. Fox And Jumping

    Codeforces题号:#510D 出处: Codeforces 主要算法:map+DP 难度:4.6 思路分析: 题意:给出n张卡片,分别有l[i]和c[i].在一条无限长的纸带上,你可以选择花c ...

随机推荐

  1. React-Native 之 GD (十三)数据持久化(realm) 及 公共Cell

    1.数据持久化 数据持久化是移动端的一个重要部分,刚发现 Realm 原来已经支持 React-Native 了 步骤一: 引入 realm $ npm install realm --save 步骤 ...

  2. easyui表格适应bootstrap

    .panel1 { overflow: hidden; text-align: left; margin:; border:; -moz-border-radius: 0 0 0 0; -webkit ...

  3. GMM demo

    # GMM model # // library(mvtnorm) ) n1 = n2 = mu1 = c(,) mu2 = c(-,-) sigma1 = matrix(c(,.,.,),nrow= ...

  4. 小刀jsonp跨域

    经常说到jsonp,今天理一理. 同源策略 同协议,同域名,同端口: 会限制你的ajax,iframe操作,窗口信息的传递,无法获取跨域的cookie.localStorage.indexDB等: j ...

  5. SpringMVC学习01——HelloSpringMvc Demo

    HelloWorldController.java文件 package com.su.controller; import org.springframework.stereotype.Control ...

  6. 分享:陆行鸟BGM合集

    第39首是原版哦 https://pan.baidu.com/mbox/homepage?short=pMkAqhX

  7. struts2 基础3 文件上传、拦截器

    文件上传: 1.将头设置为enctype=”multipart/form-data” <form action="${pageContext.request.contextPath } ...

  8. [Python3 练习] 003 货币转换

    题目:货币转换 (1) 描述 人民币和美元是世界上通用的两种货币,写一个程序进行货币间币值转换 记人民币和美元之间的汇率为:1 美元 = 6.78 人民币 程序可以接受人民币或美元输入,转换为另一种货 ...

  9. Java包的使用

    好处 1.类似于文件系统的文件夹,可以实现分类管理类文件,方便查找2.解决了同一个项目中同名类的冲突问题 包的创建 命名规范: 建议小写字母,并且采用域名倒置的写法 域名倒置:com.baidu ww ...

  10. 实现类似add(1)(2)(3)结果为6的效果

    前两天看到一个问题说怎样实现add方法实现add(1)(2)(3)结果为6,于是开始引发了我的思考. 1.想要实现add()()这样调用方式,add()方法的返回值务必是一个函数 function a ...