zoukankan      html  css  js  c++  java
  • 2019-ECfinal-M题-value

    题目传送门

    sol:每个下标都有选和不选两种情况,所以总方案数是$2^{n}$,在$n$最大是$100000$的情况下不符合要求。可以这样想,假设$i^{p}=k$有符合题目要求的解,还有一个整数$j$,$j$不是$i$的整次幂,$i$也不是$j$的整次幂,那么$j^{p}=k$不可能成立,所以我们可以把所以底数分开考虑,所以$2$的整次幂拉出来爆搜一次;所以$3$的整次幂拉出来爆搜一次;$4$因为在爆搜$2$的时候考虑过,所以跳过。。。最后加上$a[1]$就是答案了。

    • 分类讨论爆搜
      #include <bits/stdc++.h>
      using namespace std;
      typedef long long LL;
      typedef pair<int, int> PII;
      const int MAXN = 1e5 + 10;
      int a[MAXN], b[MAXN];
      bool vis[MAXN];
      int p[30], v[30], tot;
      LL dfs(int i, LL k) {
          if (i > tot) return k;
          LL res = dfs(i + 1, k); // 不取第i个 
          k += a[p[i]];
          k -= 1LL * v[i] * b[p[i]];
          for (int j = i; j <= tot; j += i) v[j] ++;
          res = max(res, dfs(i + 1, k)); // 取第i个 
          for (int j = i; j <= tot; j += i) v[j] --;
          return res; 
      }
      int main() {
          int n; scanf("%d", &n);
          for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
          for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
          LL res = a[1];
          for (int i = 2; i <= n; i++) {
              if (vis[i]) continue;
              tot =  0;
              for (LL j = i; j <= n; j *= i) {
                  p[++tot] = j;
                  vis[j] = true;
              }
              res += dfs(1, 0);
          }
          printf("%lld
      ", res);
          return 0;
      }
  • 相关阅读:
    thinkphp使用ajax
    thinkphp修改和删除数据
    thinkphp添加数据
    thinkphp中的查询语句
    thinkphp模型
    空控制器的处理
    thinkphp3.2.3版本文件目录及作用
    12月18日Smarty文件缓存
    12月15日smarty模板基本语法
    12月13日上午Smarty模版原理
  • 原文地址:https://www.cnblogs.com/Angel-Demon/p/12187621.html
Copyright © 2011-2022 走看看