D. Round Subset
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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
0
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.

每输入一个数,就把分解为x个2,和y个5,则就转化为背包问题

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 0x3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int n,k,a[][];
int dp[][];
ll x;
ll solve(ll x,ll y)
{
ll ans=;
while(x%y==)
{
ans++;
x/=y;
}
return ans;
}
int main()
{
while(scanf("%d%d",&n,&k)!=EOF)
{
memset(dp,-,sizeof(dp));
dp[][]=;
int pos=;
for(int i=;i<=n;i++)
{
scanf("%I64d",&x);
a[i][]=solve(x,);
a[i][]=solve(x,);
pos+=a[i][];
}
for(int i=;i<=n;i++)
{
for(int j=min(i,k);j>=;j--)
{
for(int z=pos;z>=a[i][];z--)
{
if(dp[j-][z-a[i][]]!=-)
dp[j][z]=max(dp[j][z],dp[j-][z-a[i][]]+a[i][]);
}
}
}
int ans=;
for(int i=;i<=pos;i++)
{
ans=max(ans,min(dp[k][i],i));
}
printf("%d\n",ans);
}
return ;
}

Codefroces Educational Round 26 837 D. Round Subset的更多相关文章

  1. Codefroces Educational Round 26 837 B. Flag of Berland

    B. Flag of Berland time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  2. Codefroces Educational Round 26 837 C. Two Seals

    C. Two Seals time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  3. CodeForces 837D - Round Subset | Educational Codeforces Round 26

    /* CodeForces 837D - Round Subset [ DP ] | Educational Codeforces Round 26 题意: 选k个数相乘让末尾0最多 分析: 第i个数 ...

  4. Educational Codeforces Round 26

    Educational Codeforces Round 26 困到不行的场,等着中午显示器到了就可以美滋滋了 A. Text Volume time limit per test 1 second ...

  5. CodeForces 837F - Prefix Sums | Educational Codeforces Round 26

    按tutorial打的我血崩,死活挂第四组- - 思路来自FXXL /* CodeForces 837F - Prefix Sums [ 二分,组合数 ] | Educational Codeforc ...

  6. CodeForces - 837E - Vasya's Function | Educational Codeforces Round 26

    /* CodeForces - 837E - Vasya's Function [ 数论 ] | Educational Codeforces Round 26 题意: f(a, 0) = 0; f( ...

  7. Educational Codeforces Round 26 [ D. Round Subset ] [ E. Vasya's Function ] [ F. Prefix Sums ]

    PROBLEM D - Round Subset 题 OvO http://codeforces.com/contest/837/problem/D 837D 解 DP, dp[i][j]代表已经选择 ...

  8. 【动态规划】【滚动数组】Educational Codeforces Round 26 D. Round Subset

    给你n个数,让你任选K个,使得它们乘起来以后结尾的0最多. 将每个数的因子2和因子5的数量求出来,记作a[i]和b[i]. 答案就是max{ min{Σa[i],Σb[i]} }(a[i],b[i]是 ...

  9. Educational Codeforces Round 26 D dp

    D. Round Subset time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

随机推荐

  1. php基础:define()定义常数函数

    define(); 常量类似变量,不同之处在于: 在设定以后,常量的值无法更改 常量名不需要开头的美元符号 ($) 作用域不影响对常量的访问 常量值只能是字符串或数字 <?php define( ...

  2. 工作日志:dispatch_once、网络缓存、分享问题

    问题描述一: 每一个接口对应的model的数据在进入对应的模块(视图)时,执行一次本地缓存加载: 执行缓存加载的实现在基类实现. 解决方案: 将dispatch_once_t设置为成员变量: 问题扩展 ...

  3. Ubuntu 18.04图形化软件包管理器

    1.ubuntu软件这个管理工具提供了一种管理您系统中软件的好方法,通过他可以很直观的查找软件安装很简单,打开终端,输入以下命令:----------------------------------- ...

  4. TP5 上传文件

    直接贴上一个完整的代码 /** * 图片上传方法 * @return [type] [description] */ /** * 1 获取到文件 * 2 验证文件的形状是不是符合上传的规则 * 3 i ...

  5. 数据库Flashback学习

    最近更新时间:2018/12/18 适用场景 数据库升级.快速构建测试环境.DG中重建主库 前置条件 1. ARCHIVELOG 模式 数据库为 mount 状态下开启,最好指定archive log ...

  6. 20180929 北京大学 人工智能实践:Tensorflow笔记07

    (完)

  7. 数据迁移工具kettle简单上手

    近期做了不少数据迁移工作,无一例外都是kettle做的,对于这些工具,我认为.够用就好,不用做特别多的研究(当然.除非你是这款工具的忠实粉丝,我相信这种没几个).kettle也不例外.在我看来就是不同 ...

  8. java调用com组件将office文件转换成pdf

    在非常多企业级应用中都涉及到将office图片转换成pdf进行保存或者公布的场景,由于pdf格式的文档方便进行加密和权限控制(类似于百度文库).总结起来眼下将office文件转换 成pdf的方法主要有 ...

  9. 关于自适应的矩形css布局

    在面试中遇到的问题,做一个自适应的宽高2:1的矩形,这个问题考察了padding的细节,padding-bottom的百分比值,相对的是该盒模型的height,设置矩形之后,里面的内容如果太多会溢出, ...

  10. Oracle 导入导出 创建用户等

    localhost:1158/emD:\app\Administrator\product\11.2.0\dbhome_1\bin\imp.exe log  path  E:\app\Administ ...