Codeforces 837D

来源:互联网 发布:阿里云邮件服务器设置 编辑:程序博客网 时间:2024/06/06 04:19

题意:给出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);      }