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 ...
随机推荐
- C# U盘扫描
无意中看到的一个例程,保留一份. 以供后用. using System; using System.Collections.Generic; using System.ComponentM ...
- (十三)springMvc 处理 Json
目录 文章目录 为什么用 Json 处理 json 的流程 环境准备 配置 json 转换器 后记 更新 为什么用 Json Json 格式简单,语法简单,解析简单 : 处理 json 的流程 判断客 ...
- 深入理解C++11 C3
继承构造函数 class A { public: A(int i):m_i(i) {} A(double d, int i):m_d(d),m_i(i){} private: int m_i{0}; ...
- ios 输入框失去焦点,位置回调方法
微信网页开发,ios 在input,textarea 失去焦点后,页面无法回调. 以下方法可解决: $("input,textarea").on("blur", ...
- JSONObject,JSONArray,对象,数组互相转化
json类型对象转化成对象类型 JSONObject.toJavaObject(jsonObj, Object.class) json类型对象转化为List类型 JSONArray.parseArra ...
- redis 入门教程
https://edu.aliyun.com/course/22/lesson/list?spm=5176.8252056.759075.5.Bbrpyz
- spring-boot-plus CORS跨域处理
CORS跨域处理 CORS:Cross-Origin Resource Sharing CORS是一种允许当前域(domain)的资源(比如html/js/web service)被其他域(domai ...
- Newtonsoft.Json基本用法
1.将一个 Object 序列化成 JSON: DataSet detail = sqlDB.GetDataSet(string.Format("select * from student ...
- C++ STL 之 容器的深拷贝和浅拷贝
如果我们没有提供拷贝构造函数,没有重载=操作符,vector 对我们的 mc 对象进行的简单的浅拷贝,将拷贝的对象插入到容器中,导致我们的 mc 对象的 data 指针和容器中mc 对象的拷贝对象中的 ...
- 【Java并发】锁机制
一.重入锁 二.读写锁 三.悲观锁.乐观锁 3.1 悲观锁 3.2 乐观锁 3.3 CAS操作方式 3.4 CAS算法理解 3.5 CAS(乐观锁算法) 3.6 CAS缺点 四.原子类 4.1 概述 ...