zoukankan      html  css  js  c++  java
  • Codefroces Educational Round 26 837 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,则就转化为背包问题

    #include <iostream> 
    #include <algorithm> 
    #include <cstring> 
    #include <cstdio>
    #include <vector> 
    #include <queue> 
    #include <cstdlib> 
    #include <iomanip>
    #include <cmath> 
    #include <ctime> 
    #include <map> 
    #include <set> 
    using namespace std; 
    #define lowbit(x) (x&(-x)) 
    #define max(x,y) (x>y?x:y) 
    #define min(x,y) (x<y?x:y) 
    #define MAX 100000000000000000 
    #define MOD 1000000007
    #define pi acos(-1.0) 
    #define ei exp(1) 
    #define PI 3.141592653589793238462
    #define ios() ios::sync_with_stdio(false)
    #define INF 0x3f3f3f3f 
    #define mem(a) (memset(a,0,sizeof(a))) 
    typedef long long ll;
    int n,k,a[205][2];
    int dp[205][10050];
    ll x;
    ll solve(ll x,ll y)
    {
        ll ans=0;
        while(x%y==0)
        {
            ans++;
            x/=y;
        }
        return ans;
    }
    int main()
    {
        while(scanf("%d%d",&n,&k)!=EOF)
        {
            memset(dp,-1,sizeof(dp));
            dp[0][0]=0;
            int pos=0;
            for(int i=1;i<=n;i++)
            {
                scanf("%I64d",&x);
                a[i][0]=solve(x,2);
                a[i][1]=solve(x,5);
                pos+=a[i][1];
            }
            for(int i=1;i<=n;i++)
            {
                for(int j=min(i,k);j>=1;j--)
                {
                    for(int z=pos;z>=a[i][1];z--)
                    {
                        if(dp[j-1][z-a[i][1]]!=-1)
                        dp[j][z]=max(dp[j][z],dp[j-1][z-a[i][1]]+a[i][0]);
                    }
                }
            }
            int ans=0;
            for(int i=1;i<=pos;i++)
            {
                ans=max(ans,min(dp[k][i],i));
            }
            printf("%d
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    dede图片横向滚动
    dede各种运用[转]
    PROFIBUS-DP现场总线的结构及应用
    51单片机的中断优先级及中断嵌套
    WPF里面制作圆角文本框
    【转】什么叫51单片机最小系统
    【转】(C#)OPC客户端源码
    路漫漫其修远兮,吾要上下左右前后而求索
    二叉树创建为什么用二级指针
    无向图的邻接表创建
  • 原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7285646.html
Copyright © 2011-2022 走看看