序号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. Java 第四天 Mysql

    下载地址 http://dev.mysql.com/downloads/  社区版是免费的 配置将zip 解压copy到本地,如:C:\mysql-5.6.15-winx64,复制配置文件my-def ...

  2. ruby on rails 实战(二)

    1,修改routes文件,让所有的action都可以使用get或者post方式访问 match "/:controller/:action" => "control ...

  3. angularjs2 学习笔记(六) Form

    Angular 2 Form表单 在angular2 form表单中我们需要了解表单数据绑定.数据验证.数据提交等内容,在下面的示例中并没有实际提交到后台,这部分内容在今后webapi中加以练习. 表 ...

  4. R语言的字符串处理

    R语言字符串的拼接 content<-paste("124235","789","124",sep="@") 运行 ...

  5. 用Python作GIS之五:从示例入手—example函数

    进入STARS后,最简单的学习方法就是演示示例数据.对于源码的分析也可以从这里入手.        以下为出发菜单项“Example Project”的函数example:def example(se ...

  6. 解决mysql登陆时出现“ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysql/mysql.sock' (2)”

    mariadb同样适用 首先检查mysql状态 linux-6yo1:~ # /etc/init.d/mysql status Checking for service MySQL: unused m ...

  7. poj 1383 Labyrinth

    题目连接 http://poj.org/problem?id=1383 Labyrinth Description The northern part of the Pyramid contains ...

  8. 54.xilinx_modelsim仿真错误1

    在仿真DDR3核时,用modelsim编译时会出现下面错误 Error:can't read "env(XILINX)":no such variable 原因:在.do文件中指定 ...

  9. 【上传AppStore】iOS项目上传到AppStore步骤流程(第二章) - 利用P12文件生成证书.多人开发必备 & 前言扫盲

    前言的前言 : 有几种关系需要搞清楚的.由我自己经历的坑和看着网上大多数资料来说,比较混乱.现在整理一下 正如前面的文章所言.一套由零 - 申请证书 - AppIDs - Provisioning P ...

  10. Linux Shel高级技巧(目录)

    Linux Shell高级技巧(一) http://www.cnblogs.com/stephen-liu74/archive/2011/12/22/2271167.html一.将输入信息转换为大写字 ...