CodeForces 837D - Round Subset | Educational Codeforces Round 26
/*
CodeForces 837D - Round Subset [ DP ] | Educational Codeforces Round 26
题意:
选k个数相乘让末尾0最多
分析:
第i个数字有a[i]个2, b[i] 个5
以其中一维作体积另一维作价值01背包即可
*/
#include <bits/stdc++.h>
using namespace std;
int dp[205][20005];
int get2(long long x)
{
int s = 0;
while (x % 2 == 0) s++, x /= 2;
return s;
}
int get5(long long x)
{
int s = 0;
while (x % 5 == 0) s++, x /= 5;
return s;
}
int n, k;
int main()
{
scanf("%d%d", &n, &k);
memset(dp, -1, sizeof(dp));
dp[0][0] = 0;
for (int i = 1; i <= n; i++)
{
long long x; scanf("%lld", &x);
int a = get2(x);
int b = get5(x);
for (int j = k; j >= 1; j--)
for (int p = a; p <= 20000; p++)
if (dp[j-1][p-a] != -1)
dp[j][p] = max(dp[j][p], dp[j-1][p-a] + b);
}
int ans = 0;
for (int i = 1; i <= 20000; i++)
if (dp[k][i] != -1)
ans = max(ans, min(i, dp[k][i]));
printf("%d\n", ans);
}
CodeForces 837D - Round Subset | Educational Codeforces Round 26的更多相关文章
- CodeForces 837F - Prefix Sums | Educational Codeforces Round 26
按tutorial打的我血崩,死活挂第四组- - 思路来自FXXL /* CodeForces 837F - Prefix Sums [ 二分,组合数 ] | Educational Codeforc ...
- 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
Educational Codeforces Round 26 困到不行的场,等着中午显示器到了就可以美滋滋了 A. Text Volume time limit per test 1 second ...
- CodeForces - 837E - Vasya's Function | Educational Codeforces Round 26
/* CodeForces - 837E - Vasya's Function [ 数论 ] | Educational Codeforces Round 26 题意: f(a, 0) = 0; f( ...
- Codeforces 837D - Round Subset(dp)
837D - Round Subset 思路:dp.0是由2*5产生的. ①dp[i][j]表示选i个数,因子2的个数为j时因子5的个数. 状态转移方程:dp[i][j]=max(dp[i][j],d ...
- Educational Codeforces Round 26 D dp
D. Round Subset time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces 837D Round Subset(背包)
题目链接 Round Subset 题意 在n个数中选择k个数,求这k个数乘积末尾0个数的最大值. 首先我们预处理出每个数5的因子个数c[i]和2的因子个数d[i] 然后就可以背包了. 设f[i] ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Educational Codeforces Round 60 (Rated for Div. 2) 题解
Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...
随机推荐
- javaweb中关于转发与重定向的写法
转发: RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/main.jsp"); rd.forward(r ...
- spring入门一:框架整体简介
1:spring的基本框架主要包含六大模块:DAO.ORM.AOP.JEE.WEB.CORE DAO:(Data Access Object) 数据访问对象,是一个面向对象的数据库接口. ORM:(O ...
- (八)springMvc 的参数绑定
参数绑定 将客户端传来的 key/value 数据,绑定到 Controller 参数的过程 : 这一过程发生在调用 处理器适配器 的时候,spring 会去调用 参数绑定 组件,我使用的版本(4.5 ...
- PID程序实现
传统PID(位置式PID控制)调节: 这种算法的缺点是,由于全量输出,每次输出均与过去的状态有关,计算时要对 e(k) 进行累加,计算机运算工作量大.而且,因为计算机输出的 u(k) 对应的是执行机构 ...
- Hexo折腾记--小白修改新主题
UPDATE 2019.5.28 不好意思我又换了个新主题ARIA啦...这回没有个人定制了 前言 如果您曾经来过我的博客,就会发现我的个人博客(https://rye-catcher.github. ...
- Spark机器学习API之特征处理(一)
Spark机器学习库中包含了两种实现方式,一种是spark.mllib,这种是基础的API,基于RDDs之上构建,另一种是spark.ml,这种是higher-level API,基于DataFram ...
- Android实习结束后的阶段性总结
2015年4月14日即将实习结束,在过去的五六个月里,对于Android开发还是学到了很多,临走前将以前做的笔记整理一下,自己也再回顾一次.零散是必然的,也可能只是一小段代码片段,但都是曾经我在学An ...
- Jerry Wang在SAP社区上获得的徽章
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
- ngnix反向代理后获取用户真实ip及https配置
server {listen 80;listen 802;server_name test111.xxxx.com 118.24.122.101; gzip on;gzip_min_length 10 ...
- PHP扩展模块php_igbinary和php_redis的安装
php_igbinary : 在序列化和反序列化的效率上高于其自带的 php_redis :效率是相当高有链表排序功能 详情略 安装之前要准备 百度网盘: wampserver2.5-A ...