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;
    }
  • 相关阅读:
    matlab中输入x. 与x的区别
    nginx 访问控制之deny allow
    nginx 反向代理之 负载均衡
    http 缓存机制简介
    nginx 反向代理之 proxy_cache
    nginx 反向代理之 proxy_buffering
    nginx 反向代理之 proxy_redirect
    nginx 反向代理之 proxy_set_header
    nginx 反向代理之 proxy_pass
    nginx 反向代理配置示例
  • 原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7285646.html
Copyright © 2011-2022 走看看