Advertisement
Josif_tepe

Untitled

May 30th, 2024
730
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. int n, x, y, z;
  2.    int dp[10055];
  3. int rec(int at) {
  4.     if(at == 0) {
  5.         return 0;
  6.     }
  7.     if(dp[at] != -1) {
  8.         return dp[at];
  9.     }
  10.     int res = -2e7;
  11.     if(at - x >= 0) {
  12.         res = max(res, rec(at - x) + 1);
  13.     }
  14.     if(at - y >= 0) {
  15.         res = max(res, rec(at - y) + 1);
  16.     }
  17.     if(at - z >= 0) {
  18.         res = max(res, rec(at - z) + 1);
  19.     }
  20.     return dp[at] = res;
  21. }
  22. int maximizeTheCuts(int n, int x, int y, int z)
  23.     {
  24.         this->n = n;
  25.         this->x = x;
  26.         this->y = y;
  27.         this->z = z;
  28.         memset(dp, -1, sizeof dp);
  29.         return rec(n) > 0 ? rec(n) : 0;
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement