【dp】codeforces 837D Round Subset
Link:http://codeforces.com/problemset/problem/837/D
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
/*
codeforces 837D Round Subset
題意:找出一個包含k個數的子集,使k個數相乘末尾的0最多。
題解:
dp[i][j] 代表取i個有j個2的最大的5的個數
dp[i][j] = max(dp[i][j],dp[i-1][j-a[g]]+b[g]);
*/
const int N = 210;
const int INF = 0x3f3f3f3f;
int a[N],b[N];
int dp[N][N*65];
int main()
{
int n,k;
scanf("%d%d",&n,&k);
LL x;
for(int i = 1; i <= n; i++)
{
scanf("%I64d",&x);
int num = 0;
while(x%2==0)
{
x/=2;
num++;
}
a[i] = num;
num = 0;
while(x%5==0)
{
x/=5;
num++;
}
b[i] = num;
// printf("%d %d\n",a[i],b[i]);
}
memset(dp,-INF,sizeof(dp));
dp[0][0] = 0;
for(int g = 1; g <= n; g++)
{
for(int i = min(k,g); i >= 1; i--)
{
for(int j = a[g]; j < N*65; j++)
dp[i][j] = max(dp[i][j],dp[i-1][j-a[g]]+b[g]);
}
}
int ans = 0;
for(int i = 1; i < N*65; i++)
ans = max(ans,min(i,dp[k][i]));
printf("%d\n",ans);
return 0;
}
相關文章
- Codeforces Round #358 (Div. 2) D dp
- Codeforces Round #316 (Div. 2) E dp
- Codeforces Round #321 (Div. 2) D 狀壓dp
- Codeforces Round #336 (Div. 2) D 區間dp
- Codeforces Round #336 (Div. 2) C 二分+dp
- Codeforces Round #360 (Div. 2) E dp 類似01揹包
- 樹形dp - Codeforces Round #322 (Div. 2) F Zublicanes and Mumocrates
- Educational Codeforces Round 167 (Rated for Div. 2) D(dp,貪心)
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) D 雙向dp
- Codeforces Round #174
- Codeforces Round #170
- Codeforces Round 955
- Codeforces Global Round 13
- Educational Codeforces Round 32
- Codeforces Beta Round #32
- Codeforces Beta Round #23
- Codeforces Round #180
- Codeforces Global Round 26
- Codeforces Global Round 27
- Codeforces Educational Round#98 A
- Educational Codeforces Round 1 Tutorial
- Codeforces Global Round 26 (A - D)
- Educational Codeforces Round 163
- Codeforces Round 962(Div .3)
- codeforces Educational Codeforces Round 33 (Rated for Div. 2)
- 【CodeForces訓練記錄】Codeforces Global Round 27
- codeforces 148 D 概率dp
- codeforces455A Boredom (裸DP)
- Codeforces Round #639 (Div. 2)
- Uncowed Forces Codeforces Round #334
- Codeforces Round #541 (Div. 2)
- Codeforces Round #690 (Div. 3)
- Codeforces Round #682 (Div. 2)
- Codeforces Round #678 (Div. 2)
- 【題解】Educational Codeforces Round 82
- Codeforces Round #747 (Div. 2)
- Codeforces Round #673 (Div. 2)
- Codeforces Round #672 (Div. 2)