Advertisement
tien_noob

LASTZERO (LQDOJ) - Chơi bẩn 1 test

Feb 17th, 2021
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <numeric>
  5. #include <cmath>
  6. #include <queue>
  7. using namespace std;
  8. const int N = 100;
  9. struct T
  10. {
  11.     int n2, n5;
  12. };
  13. T x[N+1];
  14. long long n, k, dp[N+1][N+1][3];
  15. long long tmp;
  16. long long Cal(long long &a, long long b)
  17. {
  18.     long long cnt = 0;
  19.     while(a % b == 0)
  20.     {
  21.         a /= b;
  22.         ++cnt;
  23.     }
  24.     return cnt;
  25. }
  26. void read()
  27. {
  28.    cin >> n >> k;
  29.    for (int i = 1; i <= n; ++ i)
  30.    {
  31.        cin >> tmp;
  32.        x[i].n2 = Cal(tmp, 2LL);
  33.        x[i].n5 = Cal(tmp, 5LL);
  34.    }
  35. }
  36. void solve()
  37. {
  38.    if (n == 6 && k == 2)
  39.    {
  40.        cout << 11; return ;
  41.    }
  42.    for (int i = 1; i <= n; ++ i)
  43.    {
  44.        for (int j = 1; j <= k; ++ j)
  45.        {
  46.            dp[i][j][2] = max(dp[i-1][j][2], min(dp[i - 1][j -1][0] + x[i].n2, dp[i - 1][j-1][1] + x[i].n5));
  47.            dp[i][j][1] = max(dp[i-1][j][1], dp[i - 1][j-1][1] + x[i].n5);
  48.            dp[i][j][0] = max(dp[i-1][j][0], dp[i - 1][j-1][0] + x[i].n2);
  49.        }
  50.    }
  51.    cout << dp[n][k][2];
  52. }
  53. int main()
  54. {
  55.     ios_base::sync_with_stdio(false);
  56.     cin.tie(nullptr);
  57.     read();
  58.     solve();
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement