zoukankan      html  css  js  c++  java
  • CF510 D

    题意:n个数中任取几个数,使之GCD = 1,且权值最小

    思路:暴力。。 这种方法挺好。。 学习了。。

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstdlib>
     4 #include<cstring>
     5 #include<string>
     6 #include<queue>
     7 #include<algorithm>
     8 #include<map>
     9 #include<iomanip>
    10 #include<climits>
    11 #include<string.h>
    12 #include<numeric>
    13 #include<cmath>
    14 #include<stdlib.h>
    15 #include<vector>
    16 #include<stack>
    17 #include<set>
    18 #define FOR(x, b, e)  for(int x=b;x<=(e);x++)
    19 #define REP(x, n)     for(int x=0;x<(n);x++)
    20 #define INF 1e7
    21 #define MAXN 100010
    22 #define maxn 1000010
    23 #define Mod 1000007
    24 #define N 110
    25 using namespace std;
    26 typedef long long LL;
    27 
    28 int main()
    29 {
    30     int n, tmp;
    31     cin >> n;
    32     vector<int> l, c;
    33     REP(i, n) {
    34         cin >> tmp;
    35         l.push_back(tmp);
    36     }
    37     REP(i, n) {
    38         cin >> tmp;
    39         c.push_back(tmp);
    40     }
    41     map<int, int> Gcd;
    42     Gcd[0] = 0;
    43     REP(i, n) {
    44         for (map<int, int> :: iterator it = Gcd.begin();it != Gcd.end(); ++ it) {
    45             int g = __gcd((*it).first,l[i]);
    46             Gcd[g] = min(Gcd[g] ? Gcd[g]:1<<29, (*it).second + c[i]);
    47         }
    48     }
    49     if (Gcd[1] == 0) 
    50         cout << -1 << endl;
    51     else 
    52         cout << Gcd[1] << endl;
    53     return 0;
    54 }
  • 相关阅读:
    php 函数strpos()
    uploadfy api中文文档
    thinkphp + 美图秀秀api 实现图片裁切上传,带数据库
    mysql 操作用户权限
    window.location 小结)
    turn.js 图书翻页效果
    thinkphp 内置标签volist 控制换行
    js 数据类型转换
    quartz 2.2.1
    Mysql测试链接
  • 原文地址:https://www.cnblogs.com/usedrosee/p/4386259.html
Copyright © 2011-2022 走看看