Function to test above algorithm.
71 {
72
73 const int16_t n1 = 8;
75 const int64_t max_profit1 =
77 const int64_t expected_max_profit1 = 47;
78 assert(max_profit1 == expected_max_profit1);
79 std::cout <<
"Maximum profit with " << n1 <<
" inch road is " << max_profit1
81
82
83 const int16_t n2 = 30;
85 1, 5, 8, 9, 10, 17, 17, 20, 24, 30,
86 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
87 41, 42, 43, 44, 45, 46, 47, 48, 49, 50};
88
89 const int64_t max_profit2=
91 const int32_t expected_max_profit2 = 90;
92 assert(max_profit2 == expected_max_profit2);
93 std::cout <<
"Maximum profit with " << n2 <<
" inch road is " << max_profit2
95
96 const int16_t n3 = 5;
98 const int64_t max_profit3 =
100 const int64_t expected_max_profit3 = 45;
101 assert(max_profit3 == expected_max_profit3);
102 std::cout <<
"Maximum profit with " << n3 <<
" inch road is " << max_profit3
104}
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:44