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 }
  • 相关阅读:
    SQL Server 系统视图
    T-SQL 批处理
    T-SQL游标
    SQL Server执行计划的理解
    SQL Server 非聚集索引的覆盖,连接,交叉和过滤 <第二篇>
    SQL Server 分区表
    SQL Server 文件和文件组
    SQL Server逻辑读、预读和物理读
    mysql 报错ERROR 1064 (42000),原因使用了mysql保留字 (right syntax to use near 'groups)
    docker Redis的主从配置
  • 原文地址:https://www.cnblogs.com/z-712/p/7307693.html
Copyright © 2011-2022 走看看