Codeforces 837D - Round Subset DP

Posted Aragaki

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces 837D - Round Subset DP相关的知识,希望对你有一定的参考价值。

 先算出每个数的pop1(twonum),pop(fivenum)然后DP ans[i][j]表示选i个数有j个2时最多有多少个5

转移方程是

        for(int j=k;j>=1;j--)
        {
        for(int w=pop1;w<5000;w++)
        {
        ans[j][w]=max(ans[j][w],ans[j-1][w-pop1]+pop);
        }
        }

AC程序:

#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#include<queue>
#define EPS 1.0e-9
#define PI acos(-1.0)
#define INF 30000000
#define MOD 1000000007
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define pai pair<int,int>
//using ll = long long;
//using ull= unsigned long long;
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
typedef long long ll;
typedef unsigned long long ull;
const int maxn=1005;
struct num
{
  int two;
  int five;
}number[205];
ll ans[205][5001];
int main()
{
        mem(ans,-1);
        ans[0][0]=0;
    int n;
    int k;
    cin >> n >> k;
    int now;
    int pop,pop1;
    num temp;
    for(int i=1;i<=n;i++)
        {
        pop=pop1=0;
        cin >> now;
        while(now&&now%5==0)
        {
        pop++;
        now/=5;
        }
        while(now&&now%2==0)
        {
        pop1++;
        now/=2;
        }
        for(int j=k;j>=1;j--)
        {
        for(int w=pop1;w<5000;w++)
        {
        ans[j][w]=max(ans[j][w],ans[j-1][w-pop1]+pop);
        }
        }
        }
        ll anser=0;
        for(ll i=1;i<=5000;i++)
        anser=max(anser,min(i,ans[k][i]));
        cout<<anser<<endl;
    return 0;
}

 

以上是关于Codeforces 837D - Round Subset DP的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces 837D - Round Subset DP

[CF837D] Round Subset(滚动数组,01背包)

cf837d Round Subset

Codeforces Round 521Codeforces #295(div. 1)

Codeforces Round #619 (Div. 2) Ayoub's function

VK Cup 2017 Round 3 + Codeforces Round #412