【Codeforces 837D】Round Subset
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的更多相关文章
- 【CodeForces - 1200C】Round Corridor (数论gcd)
Round Corridor Descriptions Amugae位于一个非常大的圆形走廊中.走廊由两个区域组成.内部区域等于nñ扇区,外部区域等于m米部门.在相同区域(内部或外部)的每对扇区之间 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【动态规划】Round Subset
CF837D. Round Subset Let's call the roundness of the number the number of zeros to which it ends. Yo ...
- 【51.27%】【codeforces 604A】Uncowed Forces
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【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 ...
- 【codeforces 546D】Soldier and Number Game
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 750B】New Year and North Pole
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 766D】Mahmoud and a Dictionary
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
随机推荐
- IdentityServer4 指定角色授权(Authorize(Roles="admin"))
1. 业务场景 IdentityServer4 授权配置Client中的AllowedScopes,设置的是具体的 API 站点名字,也就是使用方设置的ApiName,示例代码: //授权中心配置 n ...
- mysql +keeplive
下载tar包 ./configure --prefix=/usr/local/keepalived --with-kernel-dir=/usr/src/kernels/2.6.32-431.el6. ...
- VUE父子组件传值问题
一.父组件向子组件传递数据 组件实例的作用域是孤立的.这意味着不能(也不应该)在子组件的模板内直接引用父组件的数据.要让子组件使用父组件的数据,我们需要通过子组件的props选项. 1.静态props ...
- OGEngine_2.x中BitmapFont加载后黑屏问题的解决办法
在我使用OGEngine_2.x进行消灭圈圈(星星)游戏的实践的时候,使用BitmapFont对自定义字体进行调用. 原文字体教程如下:http://blog.csdn.net/OrangeGame/ ...
- 【Kafka源码】KafkaConsumer
[TOC] KafkaConsumer是从kafka集群消费消息的客户端.这是kafka的高级消费者,而SimpleConsumer是kafka的低级消费者.何为高级?何为低级? 我们所谓的高级,就是 ...
- Python概述与安装
Python 一门面向对象的解释性语言. Python优点 开发效率高(有丰富的各种类库,不需要重复造轮子):可移植性:解释性:免费开源:交互式(IDLE,代码写一行执行一行) Python缺点 相对 ...
- Python之numpy模块array简短学习
1.简介 Python的lists是非常的灵活以及易于使用.但是在处理科学计算相关大数量的时候,有点显得捉襟见肘了. Numpy提供一个强大的N维数组对象(ndarray),包含一些列同类型的元素,这 ...
- C#值参数和引用参数
一.值参数 未用ref或out修饰符声明的参数为值参数. 使用值参数,通过将实参的值复制到形参的方式,把数据传递到方法.方法被调用时,系统做如下操作. 在栈中为形参分配空间. 复制实参到形参. 值参数 ...
- 隐藏17年的Office远程代码执行漏洞(CVE-2017-11882)
Preface 这几天关于Office的一个远程代码执行漏洞很流行,昨天也有朋友发了相关信息,于是想复现一下看看,复现过程也比较简单,主要是简单记录下. 利用脚本Github传送地址 ,后面的参考链接 ...
- shell的逻辑运算符
一.逻辑运算符 逻辑卷标 表示意思 1. 关于档案与目录的侦测逻辑卷标! -f 常用!侦测『档案』是否存在 eg: if [ -f filename ] -d 常用!侦测『目录』是否存在 -b 侦测是 ...