Function to test above algorithm.
72 {
73
74 const int16_t n1 = 8;
76 const int64_t max_profit1 =
78 const int64_t expected_max_profit1 = 47;
79 assert(max_profit1 == expected_max_profit1);
80 std::cout <<
"Maximum profit with " << n1 <<
" inch road is " << max_profit1
82
83
84 const int16_t n2 = 30;
86 1, 5, 8, 9, 10, 17, 17, 20, 24, 30,
87 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
88 41, 42, 43, 44, 45, 46, 47, 48, 49, 50};
89
90 const int64_t max_profit2 =
92 const int32_t expected_max_profit2 = 90;
93 assert(max_profit2 == expected_max_profit2);
94 std::cout <<
"Maximum profit with " << n2 <<
" inch road is " << max_profit2
96
97 const int16_t n3 = 5;
99 const int64_t max_profit3 =
101 const int64_t expected_max_profit3 = 45;
102 assert(max_profit3 == expected_max_profit3);
103 std::cout <<
"Maximum profit with " << n3 <<
" inch road is " << max_profit3
105}
int maxProfitByCuttingRod(const std::array< int, T > &price, const uint64_t &n)
Cuts the rod in different pieces and stores the maximum profit for each piece of the rod.
Definition cut_rod.cpp:45