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 ...
随机推荐
- React-Native 之 GD (二)自定义共用导航栏样式
1.自定义导航栏样式 步骤一:从效果图中可以看出,导航栏的样式都差不多,因为我们前面已经设置了 Navigator ,这边的话我们还需要自定义 Navigator 的样式,可以看到所有的 Naviga ...
- (转)VS2010结合水晶报表做条码标签打印功能
本文转载自:http://blog.sina.com.cn/s/blog_552ca1400100y6dd.html 先来个功能效果图: 大家都知道VS2005和VS2008软件本身是包含水晶报表插件 ...
- java 操作hdfs(连接HDFS)
FileSystem fs = null; Configuration conf = null; @Before public void init() throws Exception{ conf = ...
- windows7 玩 WinKawaks kof2002为什么提示couldn't initialise DirectSound?
插上 耳机 或者 音响 就ok 呵呵 http://wenwen.sogou.com/z/q200172744.htm windows7 玩 WinKawaks kof2002为什么提示couldn ...
- 练习3-python-创造百万条数据库数据
有时候需求大批量的数据做测试支撑,如果使用传统的添加数据的方式可能比较耗费时间,利用python可以轻松的完成这项任务,还可以后续维护使用脚本. 方法1:insert into table selec ...
- redis 设置密码 和 redis.config文件
- layui的分页使用(前端分页)
<div id="one"></div>//显示数据库中数据的<ul id="ones"></ul>//显示分页 ...
- 如何解决IIS配置HTTPS证书后刷新消失问题
IIS配置CER证书后完成证书申请后刷新后就会消失的这个BUG微软一直存在,因为我们一般申请都是下来的CER文件和私钥 但是IIS只支持PFX文件的导入,所以我们需要把CER文件和证书私钥转换成PFX ...
- The second curriculum design experiment report in spring 2019
2019年第二次课程设计实验报告 一.实验项目名称 贪吃蛇 二.实验项目功能描述 1.小蛇的移动 玩家可以通过 W A S D控制小蛇的上左下右移动,通过函数改变小蛇部位的位置 2.判断游戏失败 当小 ...
- java枚举详解
枚举的本质是类,枚举是用来构建常量数据结构的模板(初学者可以以此方式理解: public static final X=xxx),枚举的使用增强了程序的健壮性,在引用一个不存在的枚举值的时候,编译器会 ...