Codeforces 837D Round Subset(背包)
题目链接 Round Subset
题意 在n个数中选择k个数,求这k个数乘积末尾0个数的最大值。
首先我们预处理出每个数5的因子个数c[i]和2的因子个数d[i]
然后就可以背包了。
设f[i][j]为选i个数,5的因子总和为j时,2的因子总和的最大值。
则状态转移方程为 $f[i][j] = max(f[i - 1][j - c[k]] + d[k])$
注意边界条件
时间复杂度$O(5200nk)$
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i)
#define MP make_pair
#define fi first
#define se second typedef long long LL; const int N = 210; int n, k, m;
LL a[N];
int b[N];
int f[N][6010];
int ans = 0;
int c[N], d[N]; int main(){ scanf("%d%d", &n, &m);
rep(i, 1, n) scanf("%lld", a + i); rep(i, 1, n){
for (; a[i] % 2 == 0; a[i] /= 2) ++d[i];
for (; a[i] % 5 == 0; a[i] /= 5) ++c[i];
} rep(j, 0, m) rep(k, 0, 5200) f[j][k] = -(1 << 30);
f[0][0] = 0; rep(i, 1, n){
dec(j, m, 1){
rep(k, c[i], 5200) f[j][k] = max(f[j][k], f[j - 1][k - c[i]] + d[i]);
}
} rep(j, 0, 5200) ans = max(ans, min(f[m][j], j));
printf("%d\n", ans);
return 0;
}
Codeforces 837D Round Subset(背包)的更多相关文章
- CodeForces 837D - Round Subset | Educational Codeforces Round 26
/* CodeForces 837D - Round Subset [ DP ] | Educational Codeforces Round 26 题意: 选k个数相乘让末尾0最多 分析: 第i个数 ...
- 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 ...
- Codeforces 837D Round Subset - 动态规划 - 数论
Let's call the roundness of the number the number of zeros to which it ends. You have an array of n ...
- Codeforces 837D - Round Subset DP
先算出每个数的pop1(twonum),pop(fivenum)然后DP ans[i][j]表示选i个数有j个2时最多有多少个5 转移方程是 ;j--) { ;w++) { ans[j][w]=max ...
- 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]代表已经选择 ...
- D - Round Subset codeforces837d
D - Round Subset 思路:背包: 代码: #include <cstdio> #include <cstring> #include <iostream&g ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #62 题解【ABCD】
Codeforces Beta Round #62 A Irrational problem 题意 f(x) = x mod p1 mod p2 mod p3 mod p4 问你[a,b]中有多少个数 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
随机推荐
- C# 使用Epplus导出Excel [3]:合并列连续相同数据
C# 使用Epplus导出Excel [1]:导出固定列数据 C# 使用Epplus导出Excel [2]:导出动态列数据 C# 使用Epplus导出Excel [3]:合并列连续相同数据 C# 使用 ...
- js之数组知识
一.数组的定义(来源于Array.prototype) 1.构造函数方法: (1)var arr = new Array();//没有参数等价于 var arr = []; (2)var arr = ...
- DP入门练习
T1 题目:codevs4815江哥的dp题a codevs4815 一个简单的DP,注意开long long(不然会全WA),以及初始条件(这题有负数,所以要把f设成极小值.还要保证转移正确). # ...
- python中函数定义之实参、形参
一般在函数的定义中,会有一类变量---形参,它是函数完成其工作的一项信息.实参往往是调用函数时传递给函数的信息.我们在调用函数时,将要让函数使用的信息放在括号内.例如定义一个函数def greet_u ...
- 搭建pip源
1.安装pip软件 yum -y install python-pippip install --upgrade pippip install pip2pi 2.安装apacheyum -y inst ...
- verilog behavioral modeling--sequential and parallel statements
1.Sequential statement groups the begin-end keywords: .group several statements togethor .cause the ...
- (转)编写高质量的OC代码
点标记语法 属性和幂等方法(多次调用和一次调用返回的结果相同)使用点标记语法访问,其他的情况使用方括号标记语法. 良好的风格: view.backgroundColor = [UIColor or ...
- uboot的Makefile裁剪(针对飞思卡尔的mx6系列)
VERSION = 2009PATCHLEVEL = 08SUBLEVEL =EXTRAVERSION =ifneq "$(SUBLEVEL)" ""U_BOO ...
- 关于get_magic_quotes_gpc()函数
function sqlReplace($str) { $strResult = $str; if(!get_magic_quotes_gpc()) //如果 gpc 没有开的话 { $strResu ...
- 【javascript面试题】5个经典的面试题
问题1: 作用域 看一下下面的代码: (function(){ var a = b =5; })(); console.log(b); 结果会输出什么? 答案: 5 这个问题考查的要点是两个不同的作用 ...