Codeforces_512_B
http://codeforces.com/problemset/problem/512/B
dp题,因为状态很多,所以用map保存,注意代码中的那个二层循环不能内外换,因为map会自动排序。
#include<iostream>
#include<cstdio>
#include<map>
using namespace std; int gcd(int a,int b)
{
return b?gcd(b,a%b):a;
} int l[],c[]; int main()
{
int n;
cin >> n;
for(int i = ;i <= n;i++) cin >> l[i];
for(int i = ;i <= n;i++) cin >> c[i];
map<int,int> mp;
mp.clear();
map<int,int>::iterator it;
mp[] = ;
for(int i = ;i <= n;i++)
{
for(it = mp.begin();it != mp.end();it++)
{
int temp = gcd(l[i],it->first);
if(mp.count(temp)) mp[temp] = min(mp[temp],it->second+c[i]);
else mp[temp] = it->second+c[i];
}
}
if(mp.count()) printf("%d\n",mp[]);
else printf("-1\n");
return ;
}
Codeforces_512_B的更多相关文章
随机推荐
- C++装饰器模式
UML图: #include <iostream> #include <string> #include <windows.h> using namespace s ...
- SCU 4438 Censor|KMP变形题
传送门 Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text P. He ...
- 《C++Primer》第五版习题解答--第四章【学习笔记】
[C++Primer]第五版习题解答--第四章[学习笔记] ps:答案是个人在学习过程中书写,可能存在错漏之处,仅作参考. 作者:cosefy Date: 2020/1/11 第四章:表达式 练习4. ...
- C#调用Matlab生成的Dll
问题描述:最近开发需要调用matlab生成的DLL,在New MWNumericArray 对象的时候报错,提示未将对象引用到对象的实例. 问题分析:因为MWArray.dll是Matlab提供的DL ...
- Tensorflow内存暴涨问题
1.目前只总结出两条 创建saver实例saver = tf.train.Saver()放在循环外面 不循环初始化变量 sess.run(tf.global_variables_initializer ...
- crawler碎碎念5 豆瓣爬取操作之登录练习
import requests import html5lib import re from bs4 import BeautifulSoup s = requests.Session() #这里要提 ...
- 「扫盲」Elasticsearch
前言 只有光头才能变强. 文本已收录至我的GitHub精选文章,欢迎Star:https://github.com/ZhongFuCheng3y/3y 不知道大家的公司用Elasticsearch多不 ...
- python property()函数:定义属性
正常情况下,类包含的属性应该是隐藏的,只允许通过类提供的方法来间接的实现对类属性的访问和操作. class Person: #构造函数 def __init__(self, name): self.n ...
- Excel.Application使用手册
Excel.Application组件使用方法,适合应用于使用EXCEL组件做WEB应用开发. 转自http://bbs.xtjc.com/thread-376095-1-1.html 定制模块行为( ...
- 大叔 EF 来分析 EntityFrameworks.Data.Core 2
Extensions 1DbCommand拦截器扩展DbCommandInterceptorExtensions 2Class for IQuerable extensions methods Inc ...