http://codeforces.com/contest/837/problem/D

分解质因数,即第i个数的因子2的个数为c2[i],因子5的个数为c5[i],末尾零的个数就是min{Σc2[i],Σc5[i]}。

联想到二维背包,显然因子5的个数一定时,因子2的个数越多越好,于是令f(i,j,k)为前i个数选j个且因子5的个数共有k个时最多因子2的个数,得状转方程f(i,j,k)=max{f(i-1,j-1,k-c5[i])+c2[i],f(i-1,j,k)}。

再把第一维滚掉就能过了。

#include <iostream>
#include <cstring>
#define maxn 205
using namespace std;
typedef long long llint;
int n, v, c2[maxn], c5[maxn], cnt5 = ;
int dp[maxn][ * maxn]; // log_5(10^18)=25.75
bool avai[maxn][ * maxn];
int main()
{
ios::sync_with_stdio(false);
llint a;
cin >> n >> v;
for (int i = ; i <= n; i++)
{
cin >> a;
while (a % == )
{
c2[i]++;
a /= ;
}
while (a % == )
{
c5[i]++;
cnt5++;
a /= ;
}
} avai[][] = true;
//f(i,j,k)=max{f(i-1,j,k),f(i-1,j-1,k-c5[i])+c2[i]}
for (int i = ; i <= n; i++)
{
for (int j = min(v, i); j >= ; j--)
{
for (int k = cnt5; k >= c5[i]; k--)
{
int x = k - c5[i];
int v1 = avai[j - ][x] ? dp[j - ][x] + c2[i] : , v2 = avai[j][k] ? dp[j][k] : ;
if (avai[j][k] = avai[j - ][x] || avai[j][k])
dp[j][k] = max(v1, v2);
}
}
} int ans = ;
for (int i = ; i <= cnt5; i++)
if (avai[v][i])
ans = max(ans, min(i, dp[v][i]));
cout << ans << endl;
return ;
}

【Codeforces 837D】Round Subset的更多相关文章

  1. 【CodeForces - 1200C】Round Corridor (数论gcd)

    Round Corridor  Descriptions Amugae位于一个非常大的圆形走廊中.走廊由两个区域组成.内部区域等于nñ扇区,外部区域等于m米部门.在相同区域(内部或外部)的每对扇区之间 ...

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. 【动态规划】Round Subset

    CF837D. Round Subset Let's call the roundness of the number the number of zeros to which it ends. Yo ...

  4. 【51.27%】【codeforces 604A】Uncowed Forces

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【codeforces 742C】Arpa's loud Owf and Mehrdad's evil plan

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【codeforces 546D】Soldier and Number Game

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【codeforces 750B】New Year and North Pole

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【codeforces 766D】Mahmoud and a Dictionary

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

随机推荐

  1. 前端菜鸟学习之DOM事件处理

    一.事件处理程序 1.DOM0级事件处理程序:就是将一个函数赋值给一个事件处理程序属性,至今仍为现代所有浏览器所支持,主要得益于其跨浏览器的优势,要使用DOM0级事件 首先要得到操作对象的引用,具体实 ...

  2. 深入理解JavaScript中的继承:原型链篇

    一.何为原型链 原型是一个对象,当我调用一个对象的方法时,如果该方法没有在对象里面,就会从对象的原型去寻找.JavaScript就是通过层层的原型,形成原型链. 二.谁拥有原型 任何对象都可以有原型, ...

  3. javascript中原型链与instanceof 原理

    instanceof:用来判断实例是否是属于某个对象,这个判断依据是什么呢? 首先,了解一下javascript中的原型继承的基础知识: javascript中的对象都有一个__proto__属性,这 ...

  4. 状态码为 200 from cache和304 Not modified的区别

    1.请求状态码为 200  from cache: 表示该资源已经被缓存过,并且在有效期内,所以不再向浏览器发出请求,直接使用本地缓存. 如下图: 2.状态码为 304 Not modified: 表 ...

  5. [java基础] java 左移和右移

    今天搜到一个比较好用的在线编译器,希望和大家分享. 除了java还有c++....,地址是http://www.tutorialspoint.com/compile_java_online.php 另 ...

  6. EasyUI扩展验证

    1.首先在jquery.easyui.min.js下最后插入下面代码 $.extend($.fn.validatebox.defaults.rules, { idcard : {// 验证身份证 va ...

  7. 一起写框架-Ioc内核容器的实现-基础功能-ComponentScan支持多包扫描(六)

    实现功能 1.我们看到@ComponentScan注解一个开始定义就是需要支持,扫描多个包,将多个包的类名获取到.现在就实现这个功能. 实现思路 根据传入的字符串数组,获得多个包下的类全限制名. 实现 ...

  8. 【APP问题定位(二)】Charles定位工具

    Charles工具是APP测试中简单有使用的一款测试工具,可以通过捕获request和response的信息初步确定bug的原因所在. 本文将从安装.使用两个方面来介绍. 安装 点击这里进入下载页,注 ...

  9. python 小白(无编程基础,无计算机基础)的开发之路 day1

    本节内容 Python介绍 发展史 Python 2 or 3? 安装 Hello World程序 变量 用户输入 模块初识 .pyc是个什么鬼? 数据类型初识 数据运算 表达式if ...else语 ...

  10. 基础5.jQuery常用事件

    jQuery常用事件 1.bind() 方法 :为被选元素添加一个或多个事件处理程序,并规定事件发生时运行的函数. 2.blur() 方法:当元素失去焦点时发生 blur 事件. 3.change() ...