Codeforces 837D Round Subset :随便来个DP
来源:互联网 发布:免费申请域名建立网站 编辑:程序博客网 时间:2024/06/05 16:38
弱智题。。。辣眼睛。。不要看。。。orz
题意:给出n(<=200)个数字,每个数字<=1e18。现在取其中k(<=n)个相乘,求其末尾0个数的最大值。
题解:显然可以把数字分成2^x和5^y剩下的部分都没有用。对于每个数字记下x和y。考虑一个数字最大是10^18,最小的因子是2,所以x最大值是18/lg2 <54所以总共200个数字2的个数小于10800。用dp[ i ][ j ]表示选择了 j 个数字,总共有 i 个2,5的最大数量。然后在枚举min( i , dp[ i ][ k ] )取最大的一个就可以了
Code:
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int n, m, s;int f[10050][250];int main() {memset(f, 0x80, sizeof(f));f[0][0]=0;scanf("%d%d", &n, &m);for(int i=1; i<=n; ++i) {long long p; int x=0, y=0; scanf("%I64d", &p);for(; !(p%5); p/=5) ++x;for(; !(p%2); p/=2) ++y;s+=x;for(int k=min(i, m); k>=1; --k)for(int j=s; j>=x; --j)f[j][k]=max(f[j][k], f[j-x][k-1]+y);}int ans=0;for(int i=1; i<=s; ++i) ans=max(ans, min(i, f[i][m]));printf("%d\n", ans);return 0;}
阅读全文
0 0
- Codeforces 837D Round Subset :随便来个DP
- Codeforces-837D Round Subset(dp)
- 【dp】codeforces 837D Round Subset
- codeforces 837D Round Subset (dp)
- Codeforces-837D:Round Subset(DP)
- Codeforces 837 D Round Subset
- Codeforces 837D Round Subset【思维+Dp+滚动数组】
- 837D. Round Subset
- Educational Codeforces Round 26 D Round Subset
- Educational Codeforces Round 26 D. Round Subset 滚动数组优化DP
- Educational Codeforces Round 12 D. Simple Subset
- Educational Codeforces Round 12 D. Simple Subset
- cf Educational Codeforces Round 26 D. Round Subset
- 【DP】Codeforces837D. Round Subset
- Codeforces Round #273 (Div. 2)D dp
- Codeforces Round #358 (Div. 2) D dp
- Codeforces Beta Round #10 D. LCIS(DP)
- Educational Codeforces Round 17 D dp
- 图片加载框架简单介绍<三> Glide的基本使用
- eclipse 关联源码 android.jar
- sublime3快捷键汇总
- 3.1 Tensorflow: 批标准化(Batch Normalization)
- takePicture failed 拍照失败
- Codeforces 837D Round Subset :随便来个DP
- POJ1094:Sorting It All Out(拓扑排序)
- STL中的vector学习笔记
- 用vb.net开发的简易(通用)上位机
- Android资源获取方式
- 51Nod-1582-n叉树
- RH134-第十七节-定时任务和延时任务
- flex 布局
- 解决使用ssm框架javaweb项目的乱码问题