【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 ...
随机推荐
- Pie
Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, no ...
- Node闲谈之Buffer
在刚接触Nodejs的时候,有些概念总让学前端的我感到困惑(虽然大学的时候也是在搞后端,世界上最好的语言,you know).我可以很快理解File System,Path等带有明显功能的模块,却一下 ...
- 浅析is和as两个关键词在类型转换时的使用
is检查对象是否兼容与指定类型,返回Boolean值true或者false,值得注意的是,在使用is进行类型转换的时候是永远不会抛出异常的,例如: object o=new Object(); Boo ...
- linux使用yum的方式安装mysql实践
1.先检测是否已安装mysql ps -ef|grep mysql root : pts/ :: /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mys ...
- Scrum Meeting Alpha - 8
Scrum Meeting Alpha - 8 NewTeam 2017/11/2 地点:新主楼F座二楼 任务反馈 团队成员 完成任务 计划任务 安万贺 完成了登录API的测试和包装Pull Requ ...
- robotframework自动化系列:新增流程
刚接手项目的时候,要求所有流程在上线之前必须确保正向操作是正确的:这个时候又有新的模块需要测试,所以引入自动化测试是非常有必要的!通过对比,尝试使用RF进行自动化的回归测试. 测试中最常见的操作就是增 ...
- java面试题及答案
JAVA相关基础知识1.面向对象的特征有哪些方面 1.抽象:抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面.抽象并不打算了解全部问题,而只是选择其中的一部分,暂时 ...
- Set的常用方法(java)
一.新增:重复新增的值会被覆盖 代码: Set<String> ss=new HashSet<String>(); ss.add("a");ss.add(& ...
- [转载] JaCoCo:分析单元测试覆盖率的利器
转载自http://www.ibm.com/developerworks/cn/java/j-lo-jacoco/和http://www.cnblogs.com/chenfengmugu/p/4937 ...
- [转载] ZooKeeper实现分布式队列Queue
转载自http://blog.fens.me/zookeeper-queue/ 让Hadoop跑在云端系列文章,介绍了如何整合虚拟化和Hadoop,让Hadoop集群跑在VPS虚拟主机上,通过云向用户 ...