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.
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).
Print maximal roundness of product of the chosen subset of length k.
3 2
50 4 20
3
5 3
15 16 3 25 9
3
3 3
9 77 13
0
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.
题意:给你n个数 取出k个 ans 为k个数乘积的结果的末尾的零的个数
题解:dp[i][j] 选择i个数 因子5的个数为j 的2的个数为 dp[i][j]
1 #pragma comment(linker, "/STACK:102400000,102400000") 2 #include <bits/stdc++.h> 3 #include <cstdlib> 4 #include <cstdio> 5 #include <iostream> 6 #include <cstdlib> 7 #include <cstring> 8 #include <algorithm> 9 #include <cmath> 10 #include <cctype> 11 #include <map> 12 #include <set> 13 #include <queue> 14 #include <bitset> 15 #include <string> 16 #include <complex> 17 #define LL long long 18 #define mod 1000000007 19 using namespace std; 20 int n,k; 21 LL a[205]; 22 LL dp[205][7000]; 23 struct node{ 24 int x,y; 25 }N[205]; 26 int main() 27 { 28 memset(dp,0,sizeof(dp)); 29 scanf("%d %d",&n,&k); 30 for(int i=1; i<=n; i++) 31 scanf("%I64d",&a[i]); 32 for(int i=0;i<=k;i++) 33 for(int e=0;e<=6998;e++) 34 dp[i][e]=-1e9; 35 dp[0][0]=0; 36 LL zha; 37 int now=0,xx=0; 38 for(int i=1; i<=n; i++){ 39 zha=a[i]; 40 now=0; 41 xx=0; 42 while(zha>0){ 43 if(zha%5!=0) 44 break; 45 zha/=5; 46 now++; 47 } 48 zha=a[i]; 49 while(zha>0){ 50 if(zha%2!=0) 51 break; 52 zha/=2; 53 xx++; 54 } 55 N[i].x=now; 56 N[i].y=xx; 57 } 58 for(int i=1;i<=n;i++){ 59 for(int j=k-1;j>=0;j--){ 60 for(int e=0;e<=6998;e++) 61 dp[j+1][e+N[i].x]=max(dp[j+1][e+N[i].x],dp[j][e]+N[i].y); 62 } 63 } 64 LL maxn=0; 65 for(LL e=0;e<=6998;e++) 66 maxn=max(maxn,min(dp[k][e],e)); 67 printf("%I64d\n",maxn); 68 return 0; 69 }