【Codeforces 837D】Round Subset
http://codeforces.com/contest/837/problem/D
分解质因数,即第i个数的因子2的个数为c2[i],因子5的个数为c5[i],末尾零的个数就是min{Σc2[i],Σc5[i]}。
联想到二维背包,显然因子5的个数一定时,因子2的个数越多越好,于是令f(i,j,k)为前i个数选j个且因子5的个数共有k个时最多因子2的个数,得状转方程f(i,j,k)=max{f(i-1,j-1,k-c5[i])+c2[i],f(i-1,j,k)}。
再把第一维滚掉就能过了。
#include <iostream>
#include <cstring>
#define maxn 205
using namespace std;
typedef long long llint;
int n, v, c2[maxn], c5[maxn], cnt5 = ;
int dp[maxn][ * maxn]; // log_5(10^18)=25.75
bool avai[maxn][ * maxn];
int main()
{
ios::sync_with_stdio(false);
llint a;
cin >> n >> v;
for (int i = ; i <= n; i++)
{
cin >> a;
while (a % == )
{
c2[i]++;
a /= ;
}
while (a % == )
{
c5[i]++;
cnt5++;
a /= ;
}
} avai[][] = true;
//f(i,j,k)=max{f(i-1,j,k),f(i-1,j-1,k-c5[i])+c2[i]}
for (int i = ; i <= n; i++)
{
for (int j = min(v, i); j >= ; j--)
{
for (int k = cnt5; k >= c5[i]; k--)
{
int x = k - c5[i];
int v1 = avai[j - ][x] ? dp[j - ][x] + c2[i] : , v2 = avai[j][k] ? dp[j][k] : ;
if (avai[j][k] = avai[j - ][x] || avai[j][k])
dp[j][k] = max(v1, v2);
}
}
} int ans = ;
for (int i = ; i <= cnt5; i++)
if (avai[v][i])
ans = max(ans, min(i, dp[v][i]));
cout << ans << endl;
return ;
}
【Codeforces 837D】Round Subset的更多相关文章
- 【CodeForces - 1200C】Round Corridor (数论gcd)
Round Corridor Descriptions Amugae位于一个非常大的圆形走廊中.走廊由两个区域组成.内部区域等于nñ扇区,外部区域等于m米部门.在相同区域(内部或外部)的每对扇区之间 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【动态规划】Round Subset
CF837D. Round Subset Let's call the roundness of the number the number of zeros to which it ends. Yo ...
- 【51.27%】【codeforces 604A】Uncowed Forces
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 742C】Arpa's loud Owf and Mehrdad's evil plan
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 546D】Soldier and Number Game
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 750B】New Year and North Pole
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 766D】Mahmoud and a Dictionary
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
随机推荐
- HDU1222Wolf and Rabbit(GCD思维)
Wolf and Rabbit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- poj 2566 Bound Found
Bound Found Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 4384 Accepted: 1377 Spe ...
- Equations
Equations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- SharePoint Server 2013 安装篇 - 如何解决无法找到 .net 4.5 的问题
SharePoint Server 2013 在安装前,是不能安装 VS 等会自动安装 .net 4.5.x 以上版本的 .net Framework 的软件的.因为安装了 .net Framewor ...
- linq 在查询表达式中处理异常
在查询表达式的上下文中可以调用任何方法. 但是,我们建议避免在查询表达式中调用任何会产生副作用(如修改数据源内容或引发异常)的方法. 此示例演示在查询表达式中调用方法时如何避免引发异常,而不违反有关异 ...
- JAVAscript学习笔记 jsBOM 第七节 (原创) 参考js使用表
<html> <head> <title>day02_js</title> <script type="text/javascript& ...
- HTTP中的Range: bytes=0-
HTTP中的Range就是分段请求字节数,也是大家经常说的断点续传.Range头域可以请求实体的一个或者多个子范围,Range的值为0表示第一个字节,也就是Range计算字节数是从0开始的 表示第二个 ...
- 发放福利:原价135元/年的阿里云CDN流量包(500GB)免费送
不少朋友看过本站推荐的两篇文章:1. <阿里云全民云计算活动:云服务器ECS二折起>2. <阿里云双11优惠活动-爆款云服务器> 大部分人都说不错,很快下单购买了服务器,后续使 ...
- 页面第一次加载,JS没有效果,刷新一下就好了
问题详述:页面跳转的时候,第一个第二个页面都没有问题,跳到第三个页面,JS脚本没有起作用,刷新一下就好了. 1.猜测:第一个页面和第二个页面的JS,会对第三个页面产生影响,(因为之前没有这个问题,只改 ...
- SQL命令语句小技巧
1.[ ]的使用 当我们所要查的表是系统关键字或者表名中含有空格时,需要用[]括起来,例如新建了两个表,分别为user,user info,那么select * from user和select * ...