Codeforces 512B: Fox And Jumping
题意说的是,有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的更多相关文章
- 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 ...
- 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 ...
- CodeForces 512B(区间dp)
D - Fox And Jumping Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64 ...
- Fox And Jumping
Fox And Jumping 题目链接:http://codeforces.com/problemset/problem/512/B dp 若所选卡片能到达区间内任意点,那么所选卡片的最大公约数为1 ...
- 【codeforces 510D】Fox And Jumping
[题目链接]:http://codeforces.com/contest/510/problem/D [题意] 你可以买n种卡片; 每种卡片的花费对应c[i]; 当你拥有了第i种卡片之后; 你可以在任 ...
- 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 ...
- 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 ...
- codeforces 510B. Fox And Two Dots 解题报告
题目链接:http://codeforces.com/problemset/problem/510/B 题目意思:给出 n 行 m 列只有大写字母组成的字符串.问具有相同字母的能否组成一个环. 很容易 ...
- Codeforces510 D. Fox And Jumping
Codeforces题号:#510D 出处: Codeforces 主要算法:map+DP 难度:4.6 思路分析: 题意:给出n张卡片,分别有l[i]和c[i].在一条无限长的纸带上,你可以选择花c ...
随机推荐
- hypermesh中怎么设置支反力(反作用力)
Analysis page >> Control cards >> Global output request 勾选 SPCF 和 GPFORCE .
- find查找特殊权限用法
find查找特殊权限的用法 find選項與參數: 3. 與檔案權限及名稱有關的參數: -name filename:搜尋檔案名稱為 filename 的檔案: -size [+-]SIZE:搜尋比 S ...
- Zipf's law
w https://www.bing.com/knows/search?q=马太效应&mkt=zh-cn&FORM=BKACAI 马太效应(Matthew Effect),指强者愈强. ...
- python文件操作错误解决
1. python读取文件时提示"UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 205: illega ...
- python-笔记(操作excel)
python操作excel,python操作excel使用xlrd.xlwt和xlutils模块,xlrd模块是读取excel的,xlwt模块是写excel的,xlutils是用来修改excel的.这 ...
- ubuntu 安装 rocketmq
1.安装 rocketmq首先要有java以及maven环境,这里略过,可参考 https://www.cnblogs.com/xiaobaoTribe/p/11315011.html 安装JDK ...
- Java ——if条件语句 switch语句
本节重点思维导图 if条件语句 //如果条件表达式成立,执行语句块 if(条件表达式){ //…语句块 } 如果语句块只有一条语句,大括号可以省略,否则不能省略. 建议,不管有几条语句,都不要省略大 ...
- Learn Python the hard way, ex45 对象、类、以及从属关系
#!/usr/bin/python #coding:utf-8 # animal is-a object(yes,sort of sonfusing)look at the extra credit ...
- TNS-01106: Listener using listener name LISTENER has already been started
-- 启动监听,提示已经启动. [oracle@sh ~]$ lsnrctl startLSNRCTL for Linux: Version 12.1.0.2.0 - Production on 06 ...
- heaplog
#ifdef _DEBUG #include <stdio.h> #include <stdlib.h> #include <string.h> #define _ ...