序号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. FileOutputSream

    package cd.itcast.fileinputstream; import java.io.File; import java.io.FileNotFoundException; import ...

  2. 内存分配函数malloc、realloc、calloc、_alloca

    1.内存分配函数_alloca.malloc.realloc.calloc: _alloca 函数原型void * __cdecl _alloca(size_t); 头文件:malloc.h _all ...

  3. 9.python的布尔类型与流程控制

    布尔类型其实可以算是一种特殊的数字,下面是 help() 函数得到的帮助信息: Help on class bool in module __builtin__: class bool(int) | ...

  4. [笔记]--Oracle修改SGA大小

    1.通过spfile修改 (1)使用SYS用户以SYSDBA身份登录系统 (2)查看修改前sga_max_size,sga_target大小 show parameter sga_max_size; ...

  5. VC下的人人对弈五子棋(dos)

    #include"stdio.h"#include"stdlib.h"#include"string.h"#include "io ...

  6. DB2批处理数据导入

    这里需要两个BAT文件 first.bat @echo off @set /p databaseName=1)请输入数据库名: @set /p userName=2)请输入用户名: @set /p u ...

  7. 使用dom4j技术对xml文件的基本操作

    1.pojo类:Notice package com.green.notice.storage; import java.util.ArrayList; import java.util.List; ...

  8. 【转载】MongoDB参数

    我们可以通过mongod --help查看mongod的所有参数说明,以下是各参数的中文解释. 基本配置–quiet# 安静输出 –port arg# 指定服务端口号,默认端口27017 –bind_ ...

  9. 【转】Git常用命令备忘

    Git配置 git config --global user.name "robbin" git config --global user.email "fankai@g ...

  10. GoAhead 嵌入式web

    https://embedthis.com/goahead/ 入手了一个360  4g  wifi :使用jquery  .goahead Goahead webserver编辑 GoAhead We ...