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 ...
随机推荐
- RAMSPEED的简单测试数据 x86虚拟机 龙芯 飞腾
1. ramspeed 简介 http://alasir.com/software/ramspeed/ 官网为 2. 进行简单安装测试的步骤 . 下载 wget http://alasir.com/s ...
- http无状态和鉴权解决四种方案
http协议本身是无状态的,但是在实际的web开发中常有一些操作需要有状态.比如想要访问一些私人访问权限的文章,或者这种操作需要明确当前用户身份. 显然,最简单的方案就是每次都发送账户和密码,但是这样 ...
- 【Trie】Phone List
[题目链接]: https://loj.ac/problem/10049 [题意] 问是否存在一组公共前缀.如果存在输出“NO”,否则输出“YES” [题解] 首先建出Trie树来,然后开始记录所有的 ...
- springboot由于bean加载顺序导致的问题
先记录现象: dubbo整合zipkin时,我的配置文件是这样的 @Bean("okHttpSender") public OkHttpSenderFactoryBean okHt ...
- JAVA学习篇--静态代理VS动态代理
本篇博客的由来,之前我们学习大话设计,就了解了代理模式,但为什么还要说呢? 原因: 1,通过DRP这个项目,了解到了动态代理,认识到我们之前一直使用的都是静态代理,那么动态代理又有什么好处呢?它们二者 ...
- SQLException: #22001你知道这个错误码吗
做一个积极的人 编码.改bug.提升自己 我有一个乐园,面向编程,春暖花开! java.sql.SQLException: #22001 java.sql.SQLException: #22001 a ...
- VS显示方法引用
菜单栏 工具->选项->文本编辑器->所有语言->CodeLens 勾上即可
- JavaScript笔记(5)
1.DOM操作 常用的DOM操作 document.getElementById(id); //返回指定id的元素,通用 document.getElementsByTagName(tagName); ...
- struts-2.5.14.1中jar包引入
- chrome浏览器重新安装不了
1.打开注册表方法1. windows键 + R-->输入regedit-->回车方法2.开始-运行里输入regedit方法3.单击任务栏中windows图标,在搜索程序和文件中输入reg ...