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. 平衡二叉树(AVL树)

    参考资料 http://www.cnblogs.com/Cmpl/archive/2011/06/05/2073217.html http://www.cnblogs.com/yc_sunniwell ...

  2. Is It A Tree?

    Is It A Tree? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...

  3. 2.安装Nginx

    安装稳定版本的nginx 1.为CentOS系统安装yum仓库,创建文件 /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=htt ...

  4. html5 postMessage解决跨域、跨窗口消息传递[转载]

    原文:http://www.cnblogs.com/dolphinX/p/3464056.html 一些麻烦事儿 平时做web开发的时候关于消息传递,除了客户端与服务器传值还有几个经常会遇到的问题 1 ...

  5. 安装MongoDB启动时报错‘发生系统错误2’的解决办法

    安装数据库mongodb启动时报"发生系统错误2". 这个问题是如果你之前已经装过一次,并且两次安装目录不同,就绝对会碰到的,因为你之前安装的路径已经在注册表中生成了,并没有随着你 ...

  6. VS2013创建Windows服务

    一.创建服务 1.文件->新建->项目->windows桌面->windows服务,修改你要的项目名称.我这不改名,仍叫WindowsService1,确定. 2.其中的Pro ...

  7. SQL server中事务的四个属性特征(ACID)

    事务的概念.类型和四个特征(ACID). 1.事务(Transaction)是并发控制的单位,是用户定义的一个操作序列.这些操作要么都做,要么都不做,是一个不可分割的工作单位. 通过事务,SQL Se ...

  8. [转载] Linux curl命令详解

    转载自http://www.linuxdiyf.com/linux/2800.html 命令:curl在Linux中curl是一个利用URL规则在命令行下工作的文件传输工具,可以说是一款很强大的htt ...

  9. [转载] Netty源码分析

    转载自http://blog.csdn.net/kobejayandy/article/details/11836813 Netty提供异步的.事件驱动的网络应用程序框架和工具,用以快速开发高性能.高 ...

  10. Python之mysql数据库更新表数据接口实现

    昨天,因为项目需求要添加表的更新接口,来存储预测模型训练的数据. 先码为敬~~~~~~~ # -*- coding: utf-8 -*- import pymysql import settings ...