题目链接

题意说的是,有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. int 和 字节 相互转换

    In [10]: n = 0xf1f2 In [11]: bin(n) Out[11]: '0b1111000111110010' In [12]: n.bit_length() Out[12]: 1 ...

  2. a special kind of crossword called a word square

    w Language Log: Wordplay Watch #2: The hunt for the ten-square  http://itre.cis.upenn.edu/~myl/langu ...

  3. LinkedBlockingDeque 源码分析

    LinkedBlockingDeque LinkedBlockingDeque 能解决什么问题?什么时候使用 LinkedBlockingDeque? 1)LinkedBlockingDeque 是基 ...

  4. git全套详细教程

    git安装 首先,我们要去git的官网下载一个git安装包,双击到无关紧要的步骤我就不详细描述了,直接介绍我们关键的步骤. 选择git包含的内容和打开方式 选择都很清晰,具体情况我不是很清楚,不过选择 ...

  5. Java ——数组 选择排序 冒泡排序

    本节重点思维导图 数组 public static void main(String[] args) { int a ; a=3; int[] b; b = new int[3];//强制开辟内存空间 ...

  6. 第一章:Java语言概述与环境开发

    1.计算机高级语言按程序的执行方式可以分为编译型和解释型两种: 2.JAVA程序的执行过程必须经过先编译后解释两个步骤: 3.JAVA语言里负责执行字节码文件的是JAVA虚拟机 (Java Virtu ...

  7. ElasticSearch 基础 1

    ElasticSearch 基础=============================== 索引创建 ========================== 1. RESTFUL APIAPI 基本 ...

  8. python基础-7.2文件内置属性__doc__ __file__ __package__ __cached__ __name__

    __doc__ #py文件开头的注释文字 __file__ #当前py文件的路径 __package__ #包含文件所在包,用 . 分隔,当前文件为None,导入的其他文件:指定文件所在包,用.分隔. ...

  9. [Python3 填坑] 008 索引君的朋友 in

    目录 1. print( 坑的信息 ) 2. 开始填坑 (1) 前情提要 (2) 索引君的朋友 in 上线 (3) 既然说了 in,不妨再说一说 not in (4) 一些补充 1. print( 坑 ...

  10. [CCPC-Wannafly & Comet OJ 夏季欢乐赛(2019)]飞行棋

    题目链接:https://www.cometoj.com/contest/59/problem/E?problem_id=2714 求期望并且一堆转移基本上就是期望dp了(叉腰 照常的设dp[i]表示 ...