zoukankan      html  css  js  c++  java
  • Educational Round 26 D. Round Subset

    D. Round Subset
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Let's call the roundness of the number the number of zeros to which it ends.

    You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.

    Input

    The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).

    The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).

    Output

    Print maximal roundness of product of the chosen subset of length k.

    Examples
    Input
    3 2
    50 4 20
    Output
    3
    Input
    5 3
    15 16 3 25 9
    Output
    3
    Input
    3 3
    9 77 13
    Output
    0
    Note

    In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1,[50, 20] — product 1000, roundness 3.

    In the second example subset [15, 16, 25] has product 6000, roundness 3.

    In the third example all subsets has product with roundness 0.

    每输入一个数,就把分解为x个2,和y个5,则就转化为背包问题

     1 #include <iostream>
     2 #include <stdio.h>
     3 using namespace std;
     4 const int INF = 0x3f3f3f3f;
     5 int dp[205][8010];
     6 int tdp[205][8010];
     7 int in[205][2];
     8 int main() {
     9     int N, K, i, j, k;
    10     scanf("%d %d", &N, &K);
    11     for (i = 1; i <= N; i++) {
    12         ll t;
    13         scanf("%lld", &t);
    14         while (t % 2 == 0) {
    15             in[i][0]++;
    16             t /= 2;
    17         }
    18         while (t % 5 == 0) {
    19             in[i][1]++;
    20             t /= 5;
    21         }
    22     }
    23 
    24     for (i = 0; i <= K; i++)
    25         for (j = 0; j <= 8000; j++) dp[i][j] = -INF;
    26             dp[0][0] = 0;
    27     for (i = 1; i <= N; i++) {
    28         for (j = 0; j <= K; j++)
    29             for (k = 0; k <= 8000; k++)
    30                 tdp[j][k] = dp[j][k];
    31         for (j = 0; j < K; j++) {
    32             for (k = 0; k <= 8000; k++) {
    33                 int j2 = j + 1, k2 = k + in[i][1];
    34                 if (k2 <= 8000) tdp[j2][k2] = max(tdp[j2][k2], dp[j][k] + in[i][0]);
    35             }
    36         }
    37         for (j = 0; j <= K; j++) for (k = 0; k <= 8000; k++) dp[j][k] = tdp[j][k];
    38     }
    39 
    40     int ans = 0;
    41     for (i = 0; i <= K; i++) for (j = 0; j <= 8000; j++) ans = max(ans, min(j, dp[i][j]));
    42     return !printf("%d
    ", ans);
    43 }
  • 相关阅读:
    linux安装 Android Studio详细教程,支持性较差,需要安装最新底层库内核的linux
    QT、QTE、qtopia区别
    Sublime Text 有哪些使用技巧
    华为5700交换机通过外部开源protal和本地aaa用户认证的一些问题
    离奇“undefined reference”错误分析与解决方案
    GNU工具链学习笔记
    gcc和ld 中的参数 --whole-archive 和 --no-whole-archive
    揭开Linux操作系统的Swap交换区之谜
    invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause
    学习JavaScript
  • 原文地址:https://www.cnblogs.com/z-712/p/7307693.html
Copyright © 2011-2022 走看看