• 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;
    }
  • 相关阅读:
    python经常使用的十进制、16进制、字符串、字节串之间的转换(长期更新帖)
    axis2开发webservice之编写Axis2模块(Module)
    Android中的动画具体解释系列【2】——飞舞的蝴蝶
    湘潭邀请赛——Alice and Bob
    ZOJ 2859 二维线段树
    jsp导出身份证到excel时候格式不正确
    Android 自己定义View须要重写ondraw()等方法
    聚合类新闻client产品功能点详情分析
    vi下对齐代码的操作
    最新研发的基于Java的高速开发平台
  • 原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7285646.html
Copyright © 2020-2023  润新知