题目大意:给你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. mysql运行警告

    警告信息: Fri Oct 28 09:33:35 CST 2016 WARN: Establishing SSL connection without server's identity verif ...

  2. C# Winform中慎用Application.DoEvents

    private void Add() { ; i < ; i++) { Button button = new Button(); button.Width = ; button.Height ...

  3. Grooming Meeting及测试人员所扮演的角色

    Grooming Meeting的中文翻译是“梳理会议”,它并不是Scrum框架中标准的会议(标准会议为Planning Meeting, Daily Scrum Meeting, Review Me ...

  4. centos7 网卡命名

    CentOS6 及之前以太网网卡进行顺序命名的:多网卡如:eth0,eth1 依次.Centos7 则不同,命名规则默认是基于固件.拓扑.位置信息来分配.一.网卡命名的策略systemd对网络设备的命 ...

  5. POJ1251 Jungle Roads【最小生成树】

    题意: 首先给你一个图,需要你求出最小生成树,首先输入n个节点,用大写字母表示各节点,接着说有几个点和它相连,然后给出节点与节点之间的权值.拿第二个样例举例:比如有3个节点,然后接下来有3-1行表示了 ...

  6. AutoML相关论文

    本文为Awesome-AutoML-Papers的译文. 1.AutoML简介 Machine Learning几年来取得的不少可观的成绩,越来越多的学科都依赖于它.然而,这些成果都很大程度上取决于人 ...

  7. DockerFile解析

    ⒈是什么? DockerFile是用来构建Docker镜像的构建文件,是由一系列命令和参数构成的脚本文件. ⒉步骤 ①手动编写一个符合规范的DockerFile文件(编写) ②使用docker bui ...

  8. 无责任共享 Coursera、Udacity 等课程视频(转载)

    转载链接:https://www.zybuluo.com/illuz/note/71868 B站计划:https://www.zybuluo.com/illuz/note/832995#cs基础课程

  9. Python3学习笔记16-错误和异常

    使用try...except可以处理异常 异常处理 import sys try: print('try...') r = 10/0 print('result:',r) except ZeroDiv ...

  10. WPF通过DynamicResource的用法

    1.先在资源类库中编写:style.xaml,如下: <ResourceDictionary   xmlns="http://schemas.microsoft.com/winfx/2 ...