Codeforces 837D - Round Subset 【DP】

题意:给出n个数,让你从中选出k个数,使得它们乘积的后缀0最多,输出这个值。

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 are3 subsets of 2 numbers. [50, 4] has product 200 with roundness2,[4, 20] — product 80,roundness1,[50, 20] — product 1000,roundness3.

In the second example subset[15, 16, 25] has product 6000,roundness3.

In the third example all subsets has product withroundness0.

这题做过,但是在一些细节的地方自己又不会处理。。

    while(~scanf("%d%d",&n,&k))  
    {  
        for(int i=0;i<=k;i++)  
        for(int j=0;j<maxm;j++)  
        {  
            dp[i][j]=-INF;  
        }  
        dp[0][0]=0;  
        for(int i=0;i<n;i++)  
        {  
            int n2=0,n5=0;  
            scanf("%I64d",&x);  
            while(x%2==0) x/=2,n2++;  
            while(x%5==0) x/=5,n5++;  
            for(int j=k;j>=1;j--)  
            for(int l=n2;l<maxm;l++)  //这个地方是这样的。多做题应该就会了。
            {  
                dp[j][l]=max(dp[j][l],dp[j-1][l-n2]+n5);  
            }  
        }  
        int ans=0;  
        for(int i=1;i<maxm;i++)  
        {  
            ans=max(ans,min(i,dp[k][i]));  
        }  
        printf("%d\n",ans);  
    }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值