【题意】
给出n个数,让你从中选出k个数,使得它们乘积的后缀0最多,输出这个值。
【思路】
显然0是由2*5得来的,所以先算出一个数分解质因子后2和5的个数。
然后用dp[i][j]表示选择了i个数,且这i个数质因子中5的个数和为j时,质因子中2的个数和的最大值。状态转移方程为:
dp[j][l]=max(dp[j][l],dp[j-1][l-n5]+n2);
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define N 205
int n, k, dp[N][6000];
int two[N], five[N];
void solve()
{
memset(two, 0, sizeof(two));
memset(five, 0, sizeof(five));
memset(dp, 0xbf, sizeof(dp));
int tf=0;
for(int i=1; i<=n; i++)
{
LL x, tmp;cin>>x;tmp=x;
while(x%2==0)
{
two[i]++;
x/=2;
}
x=tmp;
while(x%5==0)
{
five[i]++;
x/=5;
tf++;
}
}
dp[0][0] = 0;
int ans = 0;
for(int i=1; i<=n; i++)
for(int j = min(k, i); j >= 1; j--)
for(int k = tf; k >= five[i]; k--)
dp[j][k] = max(dp[j][k], dp[j-1][k-five[i]]+two[i]);
for(int i = 1; i <= tf; i++)
ans = max(ans, min(dp[k][i], i));
cout << ans << endl;
}
int main()
{
while(cin>>n>>k)
{
solve();
}
return 0;
}