Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define ld long double
  4. #define pi pair<ll, ll>
  5. #define F first
  6. #define S second
  7. #define pb push_back
  8. #define PI acos(-1.0)
  9. using namespace std;
  10. ll n, k, a[222], Two[222], Five[222];
  11. int Dp[2][210][200 * 65][2], tmp, Ans;
  12. bool Pick;
  13. int main()
  14. {
  15. ios::sync_with_stdio(0);
  16. cin.tie(0); cout.tie(0);
  17. // freopen("robots.in", "r", stdin);
  18.  
  19. cin >> n >> k;
  20. for (int i=1; i<=n; i++){
  21. cin >> a[i];
  22. tmp = a[i]; while(tmp%2 == 0) Two[i]++, tmp /= 2;
  23. tmp = a[i]; while(tmp%5 == 0) Five[i]++, tmp /= 5;
  24. }
  25.  
  26. for(int i = 0; i < 2; i++)
  27. for (int j = 0; j <= k; j++)
  28. for (int t = 0; t <= 60 * n; t++)
  29. for (int x = 0; x < 2; x++)
  30. Dp[i][j][t][x] = -1e9;
  31.  
  32. for (int i = 0; i <= 65 * n; i++)
  33. Dp[(n+1)%2][0][i][0] = Dp[(n+1)%2][0][i][1] = 0;
  34.  
  35. for(int i = n; i > 0; i--)
  36. for (int j = 1; j <= k; j++)
  37. for (int t = 0; t <= 60 * n; t++){
  38. Pick = (Five[i] > t + Two[i]);
  39. tmp = min(Five[i], t + Two[i]);
  40. Dp[i%2][j][t][0] = max(Dp[(i+1)%2][j][t][0], j ? Dp[(i+1)%2][j-1][max(Five[i], t + Two[i]) - tmp][Pick] + tmp : 0);
  41. Pick = (Five[i] + t > Two[i]);
  42. tmp = min(t + Five[i], Two[i]);
  43. Dp[i%2][j][t][1] = max(Dp[(i+1)%2][j][t][1], j ? Dp[(i+1)%2][j-1][max(t + Five[i], Two[i]) - tmp][Pick] + tmp : 0);
  44. }
  45.  
  46. for (int i = 0; i <= 60 * n; i++)
  47. for (int j = 0; j < 2; j++)
  48. Ans = max(Ans, Dp[n%2][k][i][j]);
  49.  
  50. cout << Ans << '\n';
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement