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 ;
}

最新文章

  1. mysql-Federated存储方式,远程表,相当于sql server的linked server
  2. Docker三剑客之Swarm介绍
  3. 【转】win7(windows7)下java环境变量配置方法
  4. 【Stage3D学习笔记续】山寨Starling(十一):Touch事件体系
  5. java org.apache.struts.taglib.html.BEAN 没有找到
  6. linux下/proc/sysrq-trigger文件的功能
  7. libMobileGestalt与UDID
  8. javascript深入理解js闭包(转载)
  9. Codeforces 437 D. The Child and Zoo 并查集
  10. MFC中使用SDL播放音频没有声音的解决方法
  11. 实验十一 团队项目设计完善&amp;编码测试
  12. Mac上安装Docker
  13. Azure CosmosDB (12) 创建Cosmos DB并执行查询语句
  14. Flink - TypeInformation
  15. C#-VS发布网站-摘
  16. 如何解决markdown中图片上传的问题
  17. JAVA中的email正则表达式
  18. 64位linux安装32位校园网客户端
  19. 3D游戏与计算机图形学中的数学方法-视截体
  20. Serlvet学习笔记之一 ——实现servlet的3种方法

热门文章

  1. 【python小随笔】将一个列表的值,分成10个一组,遍历的时候每10个遍历一次
  2. ASP.NET Core 启用跨域请求
  3. Linux Cgroup浅析
  4. 在idea中运行GitHub项目
  5. 测试工具Fiddler(三)—— 常见功能介绍
  6. 盘一盘Tidyverse| 筛行选列之select,玩转列操作
  7. 真机调试报The executable was signed with invalid entitlements.错误
  8. ORM补充文件
  9. spring cloud的配置
  10. spring boot配置spring-data-jpa的时候报错CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is java.lang.NoSuchMethodError