Educational Codeforces Round 26 D dp
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.
题意:给你n个数 取出k个 ans 为k个数乘积的结果的末尾的零的个数
题解:dp[i][j] 选择i个数 因子5的个数为j 的2的个数为 dp[i][j]
#pragma comment(linker, "/STACK:102400000,102400000")
#include <bits/stdc++.h>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#include <complex>
#define LL long long
#define mod 1000000007
using namespace std;
int n,k;
LL a[];
LL dp[][];
struct node{
int x,y;
}N[];
int main()
{
memset(dp,,sizeof(dp));
scanf("%d %d",&n,&k);
for(int i=; i<=n; i++)
scanf("%I64d",&a[i]);
for(int i=;i<=k;i++)
for(int e=;e<=;e++)
dp[i][e]=-1e9;
dp[][]=;
LL zha;
int now=,xx=;
for(int i=; i<=n; i++){
zha=a[i];
now=;
xx=;
while(zha>){
if(zha%!=)
break;
zha/=;
now++;
}
zha=a[i];
while(zha>){
if(zha%!=)
break;
zha/=;
xx++;
}
N[i].x=now;
N[i].y=xx;
}
for(int i=;i<=n;i++){
for(int j=k-;j>=;j--){
for(int e=;e<=;e++)
dp[j+][e+N[i].x]=max(dp[j+][e+N[i].x],dp[j][e]+N[i].y);
}
}
LL maxn=;
for(LL e=;e<=;e++)
maxn=max(maxn,min(dp[k][e],e));
printf("%I64d\n",maxn);
return ;
}
Educational Codeforces Round 26 D dp的更多相关文章
- Educational Codeforces Round 26
Educational Codeforces Round 26 困到不行的场,等着中午显示器到了就可以美滋滋了 A. Text Volume time limit per test 1 second ...
- CodeForces 837D - Round Subset | Educational Codeforces Round 26
/* CodeForces 837D - Round Subset [ DP ] | Educational Codeforces Round 26 题意: 选k个数相乘让末尾0最多 分析: 第i个数 ...
- 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]代表已经选择 ...
- codeforces Educational Codeforces Round 16-E(DP)
题目链接:http://codeforces.com/contest/710/problem/E 题意:开始文本为空,可以选择话费时间x输入或删除一个字符,也可以选择复制并粘贴一串字符(即长度变为两倍 ...
- Educational Codeforces Round 60 D dp + 矩阵快速幂
https://codeforces.com/contest/1117/problem/D 题意 有n个特殊宝石(n<=1e18),每个特殊宝石可以分解成m个普通宝石(m<=100),问组 ...
- Educational Codeforces Round 15 A dp
A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 26 B,C
B. Flag of Berland 链接:http://codeforces.com/contest/837/problem/B 思路:题目要求判断三个字母是否是条纹型的,而且宽和高相同,那么先求出 ...
随机推荐
- PHP中的__toString() 是什么东西
__toString() 是魔术方法的一种,具体用途是当一个对象被当作字符串对待的时候,会触发这个魔术方法 以下说明摘自PHP官方手册 public string __toString ( void ...
- jdk8 Optional使用详解
思考: 调用一个方法得到了返回值却不能直接将返回值作为参数去调用别的方法. 原来解决方案: 我们首先要判断这个返回值是否为null,只有在非空的前提下才能将其作为其他方法的参数.这正是一些类似Guav ...
- 如何将office卸载干净
我试了控制面板卸载office软件等方法,发现一直卸载不干净. 后发现这个office的官方链接,根据这个链接的步骤就很轻松的卸载好了. https://support.office.com/zh-c ...
- CS小分队第二阶段冲刺站立会议(6月2日)
昨日成果:攻克了按钮移动的问题: 遇到问题:一开始按钮移动时候,非常慢,因为是根绝相对位移差来移动,延时很严重,后来改用用鼠标的位置作为按钮的移动位置,效果明显. 按钮的mousedown事件和mou ...
- Full GC
1,新生代:(1)所有对象创建在新生代的Eden区,当Eden区满后触发新生代的Minor GC,将Eden区和非空闲Survivor区存活的对象复制到另外一个空闲的Survivor区中.(2)保证一 ...
- 第一个spring冲刺第二天
讨论成员:王俊凯.罗凯杰.王逸辉.马志磊 地点:宿舍 话题:讨论关于安卓的控件的应用和如何调用 选题:四则运算 方向:更加实用的计算器功能,功能更加实用并且简单,没有太多的繁琐操作,可以的话会加上些趣 ...
- Firefox插件开发学习总结
2018.06.14 我们小组最初只准备开发运行在google上的知乎插件,但我们经过调研发现还有一大部分用户是使用的火狐浏览器,所以我们也准备制作火狐插件.以下是我学习了部分火狐插件制作知识后的总结 ...
- <构建之法>第一二三章感悟
第一章: 看了大概了解软件从一个想法到最终成品的一个过程.软件先是由一个想法引出的,有那个想法,你需要一个工具去做什么,根据自己想要的功能大概做一个能实现基本功能的软件,对客户提出的要求进行完善,实现 ...
- 函数调用时形参的传递也会被认为是赋值操作(继承自Object后会出现的问题)
http://blog.csdn.net/houqd2012/article/details/25070987
- 初入码田--ASP.NET MVC4 Web应用开发之一 实现简单的登录
初入码田--ASP.NET MVC4 Web应用之创建一个空白的MVC应用程序 初入码田--ASP.NET MVC4 Web应用开发之二 实现简单的增删改查 2016-07-24 一.创建T4模板,建 ...