题目大意:给你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. 使用wcf的双工模式做的一个控制台聊天app

    //wcf 服务 using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Ser ...

  2. Safari导入Chrome书签

    浏览器使用频率非常高,书签栏可以定时整理,我习惯使用Chrome,有时候也使用Safari所以难免需要同步Chrome书签到Safari 操作详见下面操作

  3. 解决bootstrap-table多次请求只触发一次的问题

    在初始化table之前,要将table销毁,否则会保留上次加载的内容 1 $("#table").bootstrapTable('destroy'); 2 $("#tab ...

  4. MySQL或MariaDB忘记root密码

    当我们忘记数据库密码时,我们可以通过如下来修改! 编辑配置文件(提前最好进行备份) 然后重启服务 systemctl restart mariadb 或者 systemctl restart mysq ...

  5. Maven入门---修改tomcat版本及端口及访问路径(四)

    Maven中通过添加插件修改tomcat版本及端口及访问路径 --------------------------------------------------------------------- ...

  6. L-BFGS算法(转载)

    转载链接:http://blog.csdn.net/itplus/article/details/21897715 前面的拟牛顿法.DFP.BFGS.L-BFGS算法简短总结一下就是: 牛顿法不仅使用 ...

  7. ansible报错Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this

    安装和配置好ansible,执行命令时报错如下 [root@test01 ansible-install]# ansible test -m shell -a 'w' >> Using a ...

  8. ES系列四、ES6.3常用api之文档类api

    1.Index API: 创建并建立索引 PUT twitter/tweet/ { "user" : "kimchy", "post_date&quo ...

  9. openwrt 分区

    下面以ar9344 16M flash为例子: uboot启动时传递给内核的参数为: bootargs=console=ttyS0,115200 root=31:02 rootfstype=jffs2 ...

  10. nagios监控客户端报错/usr/bin/perl^M: bad interpreter: No such file or directory

    nagios服务端监控客户端内存时发现监控不上 在客户端直接执行脚本,报错如下: # /usr/local/nagios/libexec/check_memory.pl -w 6% -c 3% -ba ...