tuki2501

lastzerohsg.cpp

Oct 28th, 2021
1,254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 105;
  5.  
  6. int cnt2[N], cnt5[N], dp[N][N][N * 30];
  7.  
  8. void chmax(int &a, int b) {
  9.   if (a < b) a = b;
  10. }
  11.  
  12. int main() {
  13.   cin.tie(0)->sync_with_stdio(0);
  14.   int n, k;
  15.   cin >> n >> k;
  16.   for (int i = 1; i <= n; i++) {
  17.     long long x; cin >> x;
  18.     while (x % 2 == 0) {
  19.       x /= 2;
  20.       cnt2[i]++;
  21.     }
  22.     while (x % 5 == 0) {
  23.       x /= 5;
  24.       cnt5[i]++;
  25.     }
  26.   }
  27.   for (int i = 0; i < N; i++)
  28.   for (int j = 0; j < N; j++)
  29.   for (int k = 0; k < N * 30; k++) {
  30.     dp[i][j][k] = -1e9;
  31.   }
  32.   dp[0][0][0] = 0;
  33.   for (int i = 1; i <= n; i++)
  34.   for (int j = 0; j <= min(i, k); j++)
  35.   for (int l = 0; l <= 30 * n; l++) {
  36.     dp[i][j][l] = dp[i - 1][j][l];
  37.     if (j >= 1 && l >= cnt2[i]) {
  38.       chmax(dp[i][j][l], dp[i - 1][j - 1][l - cnt2[i]] + cnt5[i]);
  39.     }
  40.   }
  41.   int ans = 0;
  42.   for (int l = 0; l <= 30 * n; l++) {
  43.     ans = max(ans, min(l, dp[n][k][l]));
  44.   }
  45.   cout << ans << '\n';
  46. }
Advertisement
Add Comment
Please, Sign In to add comment