天天看點

Codeforces 837D Round Set (二維背包dp)

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

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.

#include<algorithm> #include<iostream> #include<string> #include<map>//int dx[4]={0,0,-1,1};int dy[4]={-1,1,0,0}; #include<set>//int gcd(int a,int b){return b?gcd(b,a%b):a;} #include<vector> #include<cmath> #include<stack> #include<string.h> #include<stdlib.h> #include<cstdio> #define maxn 220 #define UB (maxn*64) #define ll __int64 #define INF 10000000 using namespace std; const int inf =0x3f3f3f3f; int n,k; ll seq[maxn]; int c2[maxn],c5[maxn]; ll dp[maxn][UB]; int main() { //scanf("%d%d",&n,&k); cin>>n>>k; for(int i=0;i<n;i++) { cin>>seq[i]; ///scanf("%I64d",&seq[i]); while(seq[i]%2==0) { seq[i]/=2; c2[i]++; } while(seq[i]%5==0) { seq[i]/=5; c5[i]++; } } memset(dp,-inf,sizeof(dp)); dp[0][0]=0; for(int i=0;i<n;i++) { for(int j=k;j>=1;j--) for(int p=c2[i];p<UB;p++) { ///ll tp=dp[j-1][p-c2[i]]; // if(tp==-1) continue; dp[j][p] = max( dp[j][p] , dp[j-1][p-c2[i]]+c5[i] ); } } ll ans=0; for(ll i=0;i<UB;i++) { ///if(dp[k][i]==-1) continue; ans=max(ans,min(dp[k][i],i)); } cout<<ans<<endl; //printf("%I64d\n",ans); return 0; }

繼續閱讀