题目链接

题意说的是,有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. 使用ZeroTier搭建大局域网利用VNC远程桌面

    ZeroTier One.msi VNC Server 6.4.1 VNC Viewer 6.19.325 Network ID 83048a0632e88e16

  2. mysql-c++连接

    1.mysql-c++连接MySQL :: Download Connector/C++ https://dev.mysql.com/downloads/connector/cpp/ 1-1VS201 ...

  3. 千万别在Java类的static块里写会抛异常的代码!

    public class Demo{ static{ // 模拟会抛异常的代码 throw new RuntimeException(); } } 如果你在Java类的static块里写这样会抛异常的 ...

  4. 002-js-cookie

    cookie操作方法 1.写cookie //JS操作cookies方法! //写cookies function setCookie(name,value) { var Days = 30; var ...

  5. javascript 跳出循环比较

    for continue 跳出当前循环,继续下一个循环 break 结束循环 forEach 不能使用continue , break return/return false 跳出当前循环,在forE ...

  6. Visual Studio格式化所有文档

    1.下载 Format All Files 2. 格式化指定类型的文件 说明: Enable Remove and Sort Usings:移除未使用过的引用+排序引用 Exclusion Patte ...

  7. BZOJ[3728]PA2014 Final Zarowki

    有n个房间和n盏灯,你需要在每个房间里放入一盏灯.每盏灯都有一定功率,每间房间都需要不少于一定功率的灯泡才可以完全照亮. 你可以去附近的商店换新灯泡,商店里所有正整数功率的灯泡都有售.但由于背包空间有 ...

  8. swiper和tab相结合

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. 2018-2-13-Windows-10-16251-添加的-api

    title author date CreateTime categories Windows 10 16251 添加的 api lindexi 2018-2-13 17:23:3 +0800 201 ...

  10. CCF CSP/CCSP报名费优惠的方法以及常见疑问

    目录 1. 本文地址 2. 认证作用 2.1. 高校认可 2.2. 赛事认可 2.3. 企业认可 3. 报名费价格及获取优惠的方法 3.1. CCF CSP 3.2. CCF CCSP 4. 语言与I ...