Codefroces Educational Round 26 837 D. Round Subset
2 seconds
256 megabytes
standard input
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.
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.
每输入一个数,就把分解为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的更多相关文章
- 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 ...
- 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 ...
- CodeForces 837D - Round Subset | Educational Codeforces Round 26
/* CodeForces 837D - Round Subset [ DP ] | Educational Codeforces Round 26 题意: 选k个数相乘让末尾0最多 分析: 第i个数 ...
- Educational Codeforces Round 26
Educational Codeforces Round 26 困到不行的场,等着中午显示器到了就可以美滋滋了 A. Text Volume time limit per test 1 second ...
- CodeForces 837F - Prefix Sums | Educational Codeforces Round 26
按tutorial打的我血崩,死活挂第四组- - 思路来自FXXL /* CodeForces 837F - Prefix Sums [ 二分,组合数 ] | Educational Codeforc ...
- CodeForces - 837E - Vasya's Function | Educational Codeforces Round 26
/* CodeForces - 837E - Vasya's Function [ 数论 ] | Educational Codeforces Round 26 题意: f(a, 0) = 0; f( ...
- 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]代表已经选择 ...
- 【动态规划】【滚动数组】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]是 ...
- Educational Codeforces Round 26 D dp
D. Round Subset time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
随机推荐
- PostgreSQL Replication之第七章 理解Linux高可用(6)
7.6 PostgreSQL和高可用性 数据库是我们日常数字生活的一部分,并期望它们快速工作. 您浏览网上论坛吗?那个帖子在数据库中.您看医生吗?您的医疗记录在数据库中.您在网上购物吗?那个货物,您的 ...
- MySQL服务启动:某些服务在未由其他服务或程序使用时将自动停止
这几天因为工作需求,需要把MySQL请出来,所以将尘封已久的MySQL进行启动.可是事与愿违,兴许是许久没有访问MySQL了,MySQL生气的不理我,并向外抛出一阵阵报错.1.其中一个是:Window ...
- MySql系列之单表查询
单表查询的语法 SELECT 字段1,字段2... FROM 表名 WHERE 条件 GROUP BY field HAVING 筛选 ORDER BY field LIMIT 限制条数 关键字的执行 ...
- Xshell查看日志的基础使用
2018\11\26 下载安装不多说,官网免费版即可,附上链接:https://www.netsarang.com/products/xsh_overview.html 打开后新建连接,输入主机ip即 ...
- Python学习笔记(2)--基本数据类型
在介绍基本数据类型之前,先说一个系统方法type():返回对象的数据类型,可以帮助我们查看系统的类型定义 python不同的版本,类型名称稍有不同,这里使用的是3.5.2版本 一.基本数据类型: 1. ...
- GenIcam标准(五)
2.8.10.Enumeration, EnumEntry Enumeration节点把一个名称(name)映射到一个索引值(index value),并实现Ienumeration接口.Enumer ...
- Objective-C中的同步线程的锁
概述 在多线程编程中往往会遇到多个线程同时访问共享的资源,这种情况我们需要通过同步线程来避免.也就是给线程加锁. 因为Objective-C是C语言的超集.,严格的来说是真超集.所以C语言当中的pth ...
- Hadoop RPC框架
1.RPC框架概述 1.1 RPC(Remote Procedure Call Protocol)--远程过程调用协议,它是一种通过网络从远程计算机程序上请求服务,而不须要了解底层网络技术的协议. R ...
- myeclipse2013 jsp编辑初始化
首先,大家可能有过这种经历.双击打开jsp编辑.它默认会打开视图,这样就使人恼火了,卡死了.所以我们能够自己设jsp的默认打开方式:打开Window-->preferences得: 搜索edit ...
- [Poi] Use Poi to Build an Index.js with Modern JavaScript Features
Poi can easily launch an index.js file simply by running the poi command. This will launch a dev-ser ...