Codeforces_512_B
2024-10-08 05:59:49
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 ;
}
最新文章
- mysql-Federated存储方式,远程表,相当于sql server的linked server
- Docker三剑客之Swarm介绍
- 【转】win7(windows7)下java环境变量配置方法
- 【Stage3D学习笔记续】山寨Starling(十一):Touch事件体系
- java org.apache.struts.taglib.html.BEAN 没有找到
- linux下/proc/sysrq-trigger文件的功能
- libMobileGestalt与UDID
- javascript深入理解js闭包(转载)
- Codeforces 437 D. The Child and Zoo 并查集
- MFC中使用SDL播放音频没有声音的解决方法
- 实验十一 团队项目设计完善&;编码测试
- Mac上安装Docker
- Azure CosmosDB (12) 创建Cosmos DB并执行查询语句
- Flink - TypeInformation
- C#-VS发布网站-摘
- 如何解决markdown中图片上传的问题
- JAVA中的email正则表达式
- 64位linux安装32位校园网客户端
- 3D游戏与计算机图形学中的数学方法-视截体
- Serlvet学习笔记之一 ——实现servlet的3种方法
热门文章
- 【python小随笔】将一个列表的值,分成10个一组,遍历的时候每10个遍历一次
- ASP.NET Core 启用跨域请求
- Linux Cgroup浅析
- 在idea中运行GitHub项目
- 测试工具Fiddler(三)—— 常见功能介绍
- 盘一盘Tidyverse| 筛行选列之select,玩转列操作
- 真机调试报The executable was signed with invalid entitlements.错误
- ORM补充文件
- spring cloud的配置
- spring boot配置spring-data-jpa的时候报错CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is java.lang.NoSuchMethodError