dmkozyrev

566.cpp

Apr 17th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <algorithm>
  3. #include <cstdint>
  4.  
  5. typedef int16_t Int;
  6.  
  7. Int solveSlow(Int max1, Int max2, Int max3, Int perShirt) {
  8.     static Int maxShirts[128][128][128];
  9.     for (Int n1 = 0; n1 <= max1; ++n1) {
  10.         for (Int n2 = 0; n2 <= max2; ++n2) {
  11.             for (Int n3 = 0; n3 <= max3; ++n3) {
  12.                 auto& maxSh = maxShirts[n1][n2][n3];
  13.                 maxSh = 0;
  14.                 Int from = std::min(n3, Int((perShirt+2)/3));
  15.                 Int to = std::max(Int(0), Int(from-2));
  16.                 for (Int last3 = from; last3 >= to; --last3) {
  17.                     Int rem = std::max(Int(0), Int(perShirt-3*last3));
  18.                     Int min2 = std::min(n2, Int(rem / 2));
  19.                     Int max2 = std::min(n2, Int((rem+1)/2));
  20.                     for (Int last2 = min2; last2 <= max2; ++last2) {
  21.                         Int last1 = std::max(Int(0), Int(perShirt-3*last3-2*last2));
  22.                         if (last1 <= n1) {
  23.                             maxSh = std::max(maxSh,Int(maxShirts[n1-last1][n2-last2][n3-last3]+1));
  24.                         }
  25.                     }
  26.                 }
  27.             }
  28.         }
  29.     }
  30.     return maxShirts[max1][max2][max3];
  31. }
  32.  
  33. int main() {
  34.     int n1, n2, n3, perShirt;
  35.     scanf("%d %d %d %d", &n1, &n2, &n3, &perShirt);
  36.     printf("%d", solveSlow(n1, n2, n3, perShirt));
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment