CF837D Round Subset 动态规划
开始的时候数据范围算错了~
我以为整个序列 2 和 5 的个数都不超过 70 ~
一个非常水的 dp
code:
#include <bits/stdc++.h>
#define M 75
#define N 201
#define LL long long
using namespace std;
void setIO(string s)
{
string in=s+".in";
string out=s+".out";
freopen(in.c_str(),"r",stdin);
freopen(out.c_str(),"w",stdout);
}
int f[N][6800];
struct node
{
int t2,t5;
}t[N];
int main()
{
// setIO("dynamic-programming");
int i,j,n,k;
scanf("%d%d",&n,&k);
memset(f,-0x3f,sizeof(f));
f[0][0]=0;
for(i=1;i<=n;++i)
{
LL x;
scanf("%lld",&x);
while(x%2==0) ++t[i].t2,x/=2;
while(x%5==0) ++t[i].t5,x/=5;
}
for(i=1;i<=n;++i)
{
for(j=i;j>=1;--j)
{
for(int p=6700;p>=t[i].t5;--p)
{
f[j][p]=max(f[j][p], f[j-1][p-t[i].t5]+t[i].t2);
}
}
}
int best=0;
for(i=1;i<=k;++i)
{
for(j=1;j<=6700;++j)
{
best=max(best,min(j, f[i][j]));
}
}
printf("%d\n",best);
return 0;
}
CF837D Round Subset 动态规划的更多相关文章
- [CF837D]Round Subset_动态规划
Round Subset 题目链接:http://codeforces.com/problemset/problem/837/D 数据范围:略. 题解: $dp$比较显然. 但是卡空间,有两种方法: ...
- Codeforces 837D Round Subset - 动态规划 - 数论
Let's call the roundness of the number the number of zeros to which it ends. You have an array of n ...
- cf837d Round Subset
设dp[i][j][k]表示前i个数中选j个并且因子含有k个2的能获得的最多的5的个数 则dp[i][j][k]=max(dp[i-1][j][k],dp[i-1][j-1][k-cnt2]+cnt5 ...
- 【动态规划】Round Subset
CF837D. Round Subset Let's call the roundness of the number the number of zeros to which it ends. Yo ...
- Codeforces 837D - Round Subset(dp)
837D - Round Subset 思路:dp.0是由2*5产生的. ①dp[i][j]表示选i个数,因子2的个数为j时因子5的个数. 状态转移方程:dp[i][j]=max(dp[i][j],d ...
- D - Round Subset codeforces837d
D - Round Subset 思路:背包: 代码: #include <cstdio> #include <cstring> #include <iostream&g ...
- Codeforces 837D Round Subset(背包)
题目链接 Round Subset 题意 在n个数中选择k个数,求这k个数乘积末尾0个数的最大值. 首先我们预处理出每个数5的因子个数c[i]和2的因子个数d[i] 然后就可以背包了. 设f[i] ...
- Codefroces Educational Round 26 837 D. Round Subset
D. Round Subset time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- CodeForces 837D - Round Subset | Educational Codeforces Round 26
/* CodeForces 837D - Round Subset [ DP ] | Educational Codeforces Round 26 题意: 选k个数相乘让末尾0最多 分析: 第i个数 ...
随机推荐
- 20191106-基于Python的对字母基数排序
基数排序 概念 基数排序的算法过程是先将待排元素补位,使其长度一致,然后按照序列中的元素的每个位数进行分桶的一种算法. 比如待排序列是数字,则将所有待比较数值(正整数)统一为同样的数位长度,数位较短的 ...
- Java同C#的语法不同之处
Java同C#的语法不同之处... [注:转载而来但原出处不详:若是您原创请联系我]1,命名空间与包 C#为了把实现相似功能的类组织在一起,引入了命名空间的概念(namespace) Java中与此对 ...
- High load average analyze
https://www.tummy.com/articles/isolating-heavy-load/ https://www.tecmint.com/understand-linux-load-a ...
- CentOS 7忘记了root密码解决方案
1.启动系统,在选择进入系统的界面按“e”进入编辑页面 2.按向下键,找到以“Linux16”开头的行,在该行的最后面输入“init=/bin/sh” 3.按“ctrl+X”组合键进入单用户模式 4 ...
- 题解-APIO2019奇怪装置
problem loj-3144 题意概要:设函数 \(f(t)\) 的返回值为一个二元组,即 \(f(t)=((t+\lfloor \frac tB\rfloor)\bmod A, t\bmod B ...
- maven一些简单常用却容易记混的命令参数-U -e -B
install 命令完成了项目编译.单元测试.打包功能,同时把打好的可执行jar包(war包或其它形式的包)布署到本地maven仓库,但没有布署到远程Maven私服仓库: deploy 命令完成了项目 ...
- Effective Java 读书笔记(五):Lambda和Stream
1 Lamdba优于匿名内部类 (1)DEMO1 匿名内部类:过时 Collections.sort(words, new Comparator<String>() { public in ...
- .net core使用CSRedisCore连接哨兵集群,并用作redis使用分布式缓存。
CSRedisCore是国内大佬出品的一个Redis-Cli-SDK. Github地址:https://github.com/2881099/csredis 使用此插件作为分布式缓存也十分简单. 一 ...
- 笔记 - C#从头开始构建编译器 - 1
视频与PR:https://github.com/terrajobst/minsk/blob/master/docs/episode-01.md 作者是 Immo Landwerth(https:// ...
- 采用localStorage做定时缓存
背景 页面采用ajax获取数据时,每访问一次就会发送一次请求向服务端获取数据,可是呢. 有些数据更新的又不频繁,所以我就想着使用localStorage进行本地存储,然后在固定间隔时在去更新数据.(下 ...