寒假222_codeforces 290 div 2 D
序号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的更多相关文章
- [CF#290 Div.1 C]Fox And Dinner(最大流)
题目:http://codeforces.com/contest/512/problem/C 题目大意:给你若干个数,让你分成k组,每组围成一个圆,使得相邻两个数和均为素数,且每组人数应>=3个 ...
- DFS Codeforces Round #290 (Div. 2) B. Fox And Two Dots
题目传送门 /* DFS:每个点四处寻找,判断是否与前面的颜色相同,当走到已走过的表示成一个环 */ #include <cstdio> #include <iostream> ...
- 找规律 Codeforces Round #290 (Div. 2) A. Fox And Snake
题目传送门 /* 水题 找规律输出 */ #include <cstdio> #include <iostream> #include <cstring> #inc ...
- 拓扑排序 Codeforces Round #290 (Div. 2) C. Fox And Names
题目传送门 /* 给出n个字符串,求是否有一个“字典序”使得n个字符串是从小到大排序 拓扑排序 详细解释:http://www.2cto.com/kf/201502/374966.html */ #i ...
- 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 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 ...
- 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 ...
- 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 ...
- CodeForces Round #290 Div.2
A. Fox And Snake 代码可能有点挫,但能够快速A掉就够了. #include <cstdio> int main() { //freopen("in.txt&quo ...
随机推荐
- Ubuntu安装wps for linux
1.WPS For Linux 2013 还是只提供了32位版本,我用的是 64位 Ubuntu,如果您也是64位系统,还需要提前安装一些32位的库文件. sudo apt-get install i ...
- System.Transaction (TransactionScope) 与 可提升 (Promotable) 交易
这是我的备份,原文请看 http://www.dotblogs.com.tw/mis2000lab/archive/2014/11/12/transactionscope_promotable_tr ...
- iOS开发常用的宏
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)#define SCREEN_HEIGHT ([UIScreen mainS ...
- 在openSUSE13.2上gem install rails -v 4.1成功,但是之后不存在rails命令解决
解决方案为,不要用sudo gem install就好了,卧槽
- JavaScrip拖动动画中的常见BUG
经常我们在用JS辛苦写完一个拖动效果之后 ,发现有各种无法用JS解决的BUG.比如拖动时DOM元素中的内容会变蓝,鼠标的指示会变为一个小+号,或disable的样式,通常这种情况一发生,我们的拖动效果 ...
- hdu 4631Sad Love Story<计算几何>
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4631 题意:依次给你n个点,每次求出当前点中的最近点对,输出所有最近点对的和: 思路:按照x排序,然后用s ...
- ORA-01078、ORA-01565、ORA-17503、ORA-29701
OS: Oracle Linux Server release 5.7 DB: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - ...
- 通过Roslyn构建自己的C#脚本
通过Roslyn构建自己的C#脚本 在下一代的C#中,一个重要的特性就是"Compiler as a Service",简单的讲,就是就是将编译器开放为一种可在代码中调用的服务.最 ...
- UI进阶 即时通讯之卸载Openfire
首先,确保你已经关掉了openfire打开终端 (在应用程序-->实用工具-->)输入以下命令sudo rm -rf /Library/PreferencePanes/Openfire.p ...
- sharepoint 2010 找不到搜索不到ad里的用户
前提条件: 1.这个用户是在ad中存在的. 2.这个用户也同步到了userprofile中. 问题现象: 在sharepoint的人员选择器中,搜索不到已经添加的用户. 可能原因: 1.有人说需要将 ...