zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 26 D dp

    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.

    题意:给你n个数 取出k个 ans 为k个数乘积的结果的末尾的零的个数

    题解:dp[i][j] 选择i个数  因子5的个数为j  的2的个数为 dp[i][j]

     1 #pragma comment(linker, "/STACK:102400000,102400000")
     2 #include <bits/stdc++.h>
     3 #include <cstdlib>
     4 #include <cstdio>
     5 #include <iostream>
     6 #include <cstdlib>
     7 #include <cstring>
     8 #include <algorithm>
     9 #include <cmath>
    10 #include <cctype>
    11 #include <map>
    12 #include <set>
    13 #include <queue>
    14 #include <bitset>
    15 #include <string>
    16 #include <complex>
    17 #define LL long long
    18 #define mod 1000000007
    19 using namespace std;
    20 int n,k;
    21 LL a[205];
    22 LL dp[205][7000];
    23 struct node{
    24     int x,y;
    25 }N[205];
    26 int main()
    27 {
    28     memset(dp,0,sizeof(dp));
    29     scanf("%d %d",&n,&k);
    30     for(int i=1; i<=n; i++)
    31         scanf("%I64d",&a[i]);
    32     for(int i=0;i<=k;i++)
    33         for(int e=0;e<=6998;e++)
    34          dp[i][e]=-1e9;
    35     dp[0][0]=0;
    36     LL zha;
    37     int now=0,xx=0;
    38     for(int i=1; i<=n; i++){
    39         zha=a[i];
    40         now=0;
    41         xx=0;
    42         while(zha>0){
    43             if(zha%5!=0)
    44                 break;
    45             zha/=5;
    46             now++;
    47         }
    48         zha=a[i];
    49         while(zha>0){
    50             if(zha%2!=0)
    51                 break;
    52             zha/=2;
    53             xx++;
    54         }
    55         N[i].x=now;
    56         N[i].y=xx;
    57     }
    58     for(int i=1;i<=n;i++){
    59         for(int j=k-1;j>=0;j--){
    60              for(int e=0;e<=6998;e++)
    61              dp[j+1][e+N[i].x]=max(dp[j+1][e+N[i].x],dp[j][e]+N[i].y);
    62         }
    63     }
    64     LL maxn=0;
    65     for(LL e=0;e<=6998;e++)
    66         maxn=max(maxn,min(dp[k][e],e));
    67     printf("%I64d
    ",maxn);
    68     return 0;
    69 }
  • 相关阅读:
    DIV圆角
    ASP.net在线购物商城系统完全解析
    javascript选中一定数量文字触发事件进行分享、转发
    javascript获取2月份天数
    新版JDBC连接SqlServer2005数据库
    一些有用的SQL Server函数
    BI(Business Intelligence)
    CASE运用
    [SQL SERVER] 跨服务器查询
    java 中的 io 系统总结
  • 原文地址:https://www.cnblogs.com/hsd-/p/7287346.html
Copyright © 2011-2022 走看看