Advertisement
Josif_tepe

Untitled

Nov 3rd, 2023
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <vector>
  4. #include <fstream>
  5. #include <cstring>
  6. using namespace std;
  7. typedef long long ll;
  8. const int maxn = 202;
  9. const int INF = 1e9;
  10. int n, k;
  11. ll arr[maxn];
  12. ll power_of_two[maxn], power_of_five[maxn];
  13.  
  14. int dp[2][maxn][5206];
  15. int main() {
  16.     ios_base::sync_with_stdio(false);
  17.     cin >> n >> k;
  18.    
  19.     for(int i = 0; i < n; i++) {
  20.         cin >> arr[i];
  21.         ll x = arr[i];
  22.         power_of_two[i] = 0;
  23.         power_of_five[i] = 0;
  24.         while(x % 2 == 0) {
  25.             power_of_two[i]++;
  26.             x /= 2;
  27.         }
  28.         while(x % 5 == 0) {
  29.             power_of_five[i]++;
  30.             x /= 5;
  31.         }
  32.     }
  33.     for(int at = n; at >= 0; at--) {
  34.         int current_at = at % 2;
  35.         int prev_at = 1 - (at % 2);
  36.         for(int taken = 0; taken <= k; taken++) {
  37.             for(int five = 0; five <= 5200; five++) {
  38.                 if(at == n or taken == 0) {
  39.                     if(taken > 0 or five > 0) {
  40.                         dp[current_at][taken][five] = -INF;
  41.                     }
  42.                     else {
  43.                         dp[current_at][taken][five] = 0;
  44.                     }
  45.                 }
  46.                 else {
  47.                     dp[current_at][taken][five] = dp[prev_at][taken][five];
  48.                     if(taken > 0) {
  49.                         dp[current_at][taken][five] = max(dp[current_at][taken][five], dp[prev_at][taken - 1][max(0, five - power_of_five[at])] + power_of_two[at]);
  50.                     }
  51.                 }
  52.             }
  53.         }
  54.     }
  55.     int res = 0;
  56.     for(int i = 0; i <= 5200; i++) {
  57.         if(dp[0][k][i] >= i) {
  58.             res = i;
  59.         }
  60.     }
  61.     cout << res << endl;
  62.     return 0;
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement