题目大意:给你n个数字(小于1e18),从n个数中取k个数字相乘,使其后缀0最多,问你后缀0最多是多少。

知道得用三维的dp[ i ] [ j ] [ k ]  第一维表示用到第 i 个数为止,j 表示从中选 j 个数,想了好久也不知道

第三维是什么,我想不到怎么总结当前状况相乘之后 0 的个数QAQ。

思路:其实后面0的个数就是相乘之后有多少个10,10可以分解成 2 * 5,这样我们只要统计每个数字中

有多少个2的因子和5的因子就好了。dp [ i ][ j ][ k ]表示,在(1 - i )之间取 j 个数,5因子的数量为 k  的

情况,2的因子的最大个数。c1[ i ] 表示第 i 个数的因子中有多少个 2 ,c2[ i ]表示有多少个5

状态转移方程 dp[ i ][ j ][ k ]=max(dp[ i ][ j ][ k ] , dp[ i -1 ][ j - 1][ k-c2[ i ] ] + c1[ i ]);    dp[ i ][ j ][ k ]=max( dp[ i ][ j ][ k ] , dp[ i - 1 ][ j ][ k ] )。

还需要注意一点要用滚动数组,不然会MLE。

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
int n,k,c1[],c2[],dp[][][];
ll a[];
void work(ll x,int id)
{
ll y=x;
int cnt=;
while(!(y&))
{
cnt++;
y>>=;
}
c1[id]=cnt;
cnt=;
while(x%==)
{
cnt++;
x/=;
}
c2[id]=cnt;
}
int main()
{
cin>>n>>k;
memset(dp,-,sizeof(dp));
for(int i=;i<=n;i++)
{
scanf("%I64d",&a[i]);
work(a[i],i);
}
for(int i=;i<=;i++)for(int j=;j<k;j++)for(int u=;u<=;u++) dp[i&][j][u]=-inf;
dp[][][]=;
for(int i=;i<=n;i++)
{
for(int u=;u<=k;u++)
{
for(int j=;j<=;j++) dp[i&][u][j]=-inf;
}
for(int u=;u<=k;u++)
{
for(int j=;j<=;j++)
{
if(j-c2[i]>= && u->=) dp[i&][u][j]=max(dp[i&][u][j],c1[i]+dp[(i+)&][u-][j-c2[i]]);
dp[i&][u][j]=max(dp[i&][u][j],dp[(i+)&][u][j]);
}
}
}
int mx=;
for(int i=;i<=;i++) mx=max(mx,min(i,dp[n&][k][i]));
cout<<mx<<endl;
return ;
}

Educational Codeforces Round 26-D. Round Subset的更多相关文章

  1. Educational Codeforces Round 26 [ D. Round Subset ] [ E. Vasya's Function ] [ F. Prefix Sums ]

    PROBLEM D - Round Subset 题 OvO http://codeforces.com/contest/837/problem/D 837D 解 DP, dp[i][j]代表已经选择 ...

  2. 【动态规划】【滚动数组】Educational Codeforces Round 26 D. Round Subset

    给你n个数,让你任选K个,使得它们乘起来以后结尾的0最多. 将每个数的因子2和因子5的数量求出来,记作a[i]和b[i]. 答案就是max{ min{Σa[i],Σb[i]} }(a[i],b[i]是 ...

  3. CodeForces 837D - Round Subset | Educational Codeforces Round 26

    /* CodeForces 837D - Round Subset [ DP ] | Educational Codeforces Round 26 题意: 选k个数相乘让末尾0最多 分析: 第i个数 ...

  4. Educational Codeforces Round 26

    Educational Codeforces Round 26 困到不行的场,等着中午显示器到了就可以美滋滋了 A. Text Volume time limit per test 1 second ...

  5. CodeForces 837F - Prefix Sums | Educational Codeforces Round 26

    按tutorial打的我血崩,死活挂第四组- - 思路来自FXXL /* CodeForces 837F - Prefix Sums [ 二分,组合数 ] | Educational Codeforc ...

  6. CodeForces - 837E - Vasya's Function | Educational Codeforces Round 26

    /* CodeForces - 837E - Vasya's Function [ 数论 ] | Educational Codeforces Round 26 题意: f(a, 0) = 0; f( ...

  7. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  8. Educational Codeforces Round 60 (Rated for Div. 2) 题解

    Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...

  9. Educational Codeforces Round 58 (Rated for Div. 2) 题解

    Educational Codeforces Round 58 (Rated for Div. 2)  题目总链接:https://codeforces.com/contest/1101 A. Min ...

  10. Educational Codeforces Round 30

    Educational Codeforces Round 30  A. Chores 把最大的换掉 view code #pragma GCC optimize("O3") #pr ...

随机推荐

  1. phpexcel 导出到xls文件的时候出现乱码解决

    在header() 前面加上ob_end_clean() 函数, 清除缓冲区, 这样就不会乱码了! <?php include 'global.php'; $ids = $_GET['ids'] ...

  2. 一个单js文件也可以运行vue

    新建一个hello.html文件,输入以下内容: <html> <head> <title></title> <script src=" ...

  3. VxWorks Fuzzing 之道:VxWorks 工控实时操作系统漏洞挖掘调试与利用揭秘

    转载:freebuf 0×00 前言 关于VxWorks,这里引用44CON议题<攻击 VxWorks:从石器时代到星际>探究 一文章中的介绍: VxWorks 是世界上使用最广泛的一种在 ...

  4. JavaScript之原生接口类设计

    //接口类         var Interface =  function(name , methods){             if(arguments.length!=2){       ...

  5. 第16月第27天 pip install virtualenv ipython sip brew search

    1. pip install virtualenv virtualenv testvir cd testvir cd Scripts activate pip https://zhuanlan.zhi ...

  6. Docker镜像命令

    ①docker images [Options] 用途:列出本地主机上的镜像 Options说明: -a:列出本地所有的镜像(含中间映像层) -q:只显示镜像ID --digests:显示镜像的摘要信 ...

  7. 【转】Python之列表生成式、生成器、可迭代对象与迭代器

    [转]Python之列表生成式.生成器.可迭代对象与迭代器 本节内容 语法糖的概念 列表生成式 生成器(Generator) 可迭代对象(Iterable) 迭代器(Iterator) Iterabl ...

  8. 【vim】删除标记内部的文字 di[标记]

    当我开始使用 Vim 时,一件我总是想很方便做的事情是如何轻松的删除方括号或圆括号里的内容.转到开始的标记,然后使用下面的语法: di[标记] 比如,把光标放在开始的圆括号上,使用下面的命令来删除圆括 ...

  9. python各种post上传文件

    1.带证书上传文件 filename = '/tmp/test.cert'hash_v = 'assumethisisahash' #这是一种流式上传的方式with open(filename, 'r ...

  10. .NET CORE 1.1 迁移到.NET 2.0正式版

    以下操作参考官方文档 1:首先你需要升级到最新版的VS 2017 15.3 升级的地方在VS右上角有个黄色的更新提醒,如果没有请挂VPN或者重新下载一个新的. 2:第二步 和之前改.NET Frame ...