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 ...
随机推荐
- .net Web获取域用户账号
HttpContext.Current.Request.LogonUserIdentity.Name //可以获取出域账号 HttpContext.Current.Request.LogonUserI ...
- 888E - Maximum Subsequence 中途相遇法
Code: #include<cstdio> #include<algorithm> #include<cstring> #include<string> ...
- mySQL主从复制实战
随着访问量的不断增加,单台MySQL数据库服务器压力不断增加,需要对MYSQL进行优化和架构改造,MYQSL优化如果不能明显改善压力情况,可以使用高可用.主从复制.读写分离来.拆分库.拆分表来进行优化 ...
- vue滚动行为
有人问道如何记录vue页面的滚动条位置,再次载入组件的时候页面滚动到记录的位置? 思路: 记录滚动条位置我们好记 我们要在组件销毁之前也就是页面跳转的时候 需要用到生命周期beforeDistory将 ...
- 【模板】后缀排序(SA数组)
[模板]后缀排序 题目背景 这是一道模板题. 题目描述 读入一个长度为 \(n\) 的由大小写英文字母或数字组成的字符串,请把这个字符串的所有非空后缀按字典序从小到大排序,然后按顺序输出后缀的第一个字 ...
- malloc()和free()的原理及实现
在C语言中只能通过malloc()和其派生的函数进行动态的申请内存,而实现的根本是通过系统调用实现的(在linux下是通过sbrk()系统调用实现). malloc()到底从哪里得到了内存空间?答案是 ...
- 七 HBase表结构设计
表结构设计之 高表 与 宽表 选择 HBase 中的表可以设计为高表(tall-narrow table) 和 宽表(flat-wide table). 高表 : ...
- 编译impala、拓展impala语法解析模块
以前也编译过,但是每次编译都忘记怎么做,然后都得重新找需要下载的文件. 编译文件:buildall.sh 如果想只编译前端可以这样运行: buildall.sh -fe_only 编译时会去S3下载一 ...
- Java中发送http的get、post请求
近期做项目中,须要把消息通过中间件的形式通过http请求的方式推送给第三方,因此用到了http协议,小编花费了一个多小时.对于http协议中的post和get请求,封装了一个工具类.以下与大家分享一下 ...
- awk技巧
1通过awk脚本执行awk程序:awk-f program_file_name input_files #!/bin/awk -f BEGIN { print "What is your n ...