D - Round Subset

 

思路:背包;

 

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
ll n,m,dp[250][10050],tmp,p2,p5,pos,sum,ans;
int main()
{
    //freopen("data.txt","r",stdin);
    scanf("%lld%lld",&n,&m);
    memset(dp,-0x7f,sizeof(dp)),dp[0][0]=0;;
    for(ll i=1;i<=n;i++)
    {
        cin>>tmp,pos=tmp,p5=0,p2=0;
        while(pos%5==0) pos/=5,p2++;
        while(tmp%2==0) tmp/=2,p5++;
        sum+=p5;
        for(ll v=min(i,m);v>=1;v--)
            for(ll e=sum;e>=p5;e--) dp[v][e]=max(dp[v][e],dp[v-1][e-p5]+p2);
    }
    for(ll i=1;i<=sum;i++) ans=max(ans,min(i,dp[m][i]));
    cout<<ans;
    return 0;
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-23
  • 2022-12-23
  • 2021-04-02
  • 2021-11-17
  • 2021-05-22
  • 2021-05-30
猜你喜欢
  • 2021-06-06
  • 2022-12-23
  • 2021-12-02
  • 2022-02-22
  • 2021-06-20
  • 2021-12-07
相关资源
相似解决方案