序号5:

想了很久的DP ,应该很简单,但是。。

题目直接转化为求n个数中选一些数GCD=1且花费最小

数比较大

map  HASH

还有一点 我们知道 GCD(X,X*Y)==X;

所以我的代码里不用考虑这点了

pasting

#include<stdio.h>
#include<algorithm>
#include<string>
#include<iostream>
#include<queue>
#include<cmath>
#include<string.h>
#include <vector>
#include<map>
using namespace std;
typedef long long ll;
map<int,int>mp;
int a[333],b[333];
#define inf 0x3f3f3f3f map<int,int>::iterator it; int gcd(int x,int y)
{
if (x%y==0) return y;
return gcd(y,x%y);
} void dfs(int x,int y)
{
if (!mp[x]) mp[x]=inf;
mp[x]=min(mp[x],y);
for (it=mp.begin();it!=mp.end();it++)
{
int tmp=(*it).first;
int v= (*it).second;
int nw=gcd(tmp,x);
if (!mp[nw]) mp[nw]=inf;
mp[nw]=min(mp[nw],v+y);
}
} int main()
{
int n;
cin>>n;
for (int i=1;i<=n;i++) cin>>a[i];
for (int i=1;i<=n;i++) cin>>b[i]; for (int i=1;i<=n;i++)
dfs(a[i],b[i]);
if (mp[1]==0) mp[1]=-1;
cout<<mp[1];
return 0;
}
												

寒假222_codeforces 290 div 2 D的更多相关文章

  1. [CF#290 Div.1 C]Fox And Dinner(最大流)

    题目:http://codeforces.com/contest/512/problem/C 题目大意:给你若干个数,让你分成k组,每组围成一个圆,使得相邻两个数和均为素数,且每组人数应>=3个 ...

  2. DFS Codeforces Round #290 (Div. 2) B. Fox And Two Dots

    题目传送门 /* DFS:每个点四处寻找,判断是否与前面的颜色相同,当走到已走过的表示成一个环 */ #include <cstdio> #include <iostream> ...

  3. 找规律 Codeforces Round #290 (Div. 2) A. Fox And Snake

    题目传送门 /* 水题 找规律输出 */ #include <cstdio> #include <iostream> #include <cstring> #inc ...

  4. 拓扑排序 Codeforces Round #290 (Div. 2) C. Fox And Names

    题目传送门 /* 给出n个字符串,求是否有一个“字典序”使得n个字符串是从小到大排序 拓扑排序 详细解释:http://www.2cto.com/kf/201502/374966.html */ #i ...

  5. 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 ...

  6. Codeforces Round #290 (Div. 2) C. Fox And Names dfs

    C. Fox And Names 题目连接: http://codeforces.com/contest/510/problem/C Description Fox Ciel is going to ...

  7. Codeforces Round #290 (Div. 2) B. Fox And Two Dots dfs

    B. Fox And Two Dots 题目连接: http://codeforces.com/contest/510/problem/B Description Fox Ciel is playin ...

  8. Codeforces Round #290 (Div. 2) A. Fox And Snake 水题

    A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...

  9. CodeForces Round #290 Div.2

    A. Fox And Snake 代码可能有点挫,但能够快速A掉就够了. #include <cstdio> int main() { //freopen("in.txt&quo ...

随机推荐

  1. Tomcat工作原理

    http://www.cnblogs.com/shootercheng/p/5838645.html

  2. 重定向语句Response.Redirect()方法与Response.RedirectPermanent()对搜索引擎页面排名的影响

    在ASP.NET中,开发人员经常使用Response.Redirect()方法,用编程的手法,将对老的URL的请求转到新的URL上.但许多开发人员没有意识到的是,Response.Redirect() ...

  3. 十天学会单片机Day3 D/A与A/D转换器

    D/A转换器 1.二进制权电阻网络型D/A转换器 基准电压Vref 数据D(d3d2d1d0) 输出模拟电压V0 i0 = Vref/8R    i1 = Vref/4R     i2 = Vref/ ...

  4. win7旗舰版在安装vs2010后向sql2008添加SQL_Server_Management详解

    原文地址:http://blog.csdn.net/bruce_zeng/article/details/8202746

  5. openstack的第二天

    今天,在公司测试了还是网络有问题. 但是用了rdo还是成功了~明天就再试试怎么开放端口进来.

  6. MTK机子修复分区信息

    这是前一个星期的事了,最近一直懒得写博客~ 此事是由于我误刷了内核,然后导致分区信息出错... 内置存储挂载不上,也找不到内置存储的分区! 如果不是star的帮助.估计俺的爪机就要返厂了!! 接下来说 ...

  7. 包(package) 与 导入(import) 语句剖析

    A) 包(package):用于将完成不同功能的类分门别类,放在不同的目录下. B)命名规则:将公司域名翻转作为包名.例如www.vmaxtam.com域名,那么包名就是com.vmaxtam 每个字 ...

  8. 算法系列5《SSF33》

    SSF33算法是以128位分组为单位进行运算,密钥长度为16字节,该算法也可以被用于安全报文传送和MAC机制密文运算. 使用SSF33算法和基于3-DES的对称加密机制使用相同长度的密钥,能够同原有的 ...

  9. Debug.print的用法

    使用Debug.print可以用来更好的调试VBA程序 通过ALT+F11代开VBA编程窗口) 插入模块,接着在窗口中输入以下代码,按F5执行 Sub Excute() Debug.Print * + ...

  10. 在 Ubuntu 13.10 中搭建Java开发环境 - 懒人版

    本文记录我在Ubuntu 13.10中搭建Java开发环境. 本文环境: Ubuntu 13.10 x64运行在Win7下的VMware Workstation 10中. 1. 安装JDK与JRE s ...