(
size_ti = 1; i <= n; i++) {
56 for(
size_tj = 1; j <= i; j++) {
57q = std::max(q, price[j - 1] + profit[i - j]);
61 constint16_t ans = profit[n];
75std::array<int32_t, n1> price1 = {1, 2, 4, 6, 8, 45, 21, 9};
76 constint64_t max_profit1 =
78 constint64_t expected_max_profit1 = 47;
79assert(max_profit1 == expected_max_profit1);
80std::cout <<
"Maximum profit with "<< n1 <<
" inch road is "<< max_profit1
84 constint16_t n2 = 30;
85std::array<int32_t, n2> price2 = {
861, 5, 8, 9, 10, 17, 17, 20, 24, 30,
8731, 32, 33, 34, 35, 36, 37, 38, 39, 40,
8841, 42, 43, 44, 45, 46, 47, 48, 49, 50};
90 constint64_t max_profit2 =
92 constint32_t expected_max_profit2 = 90;
93assert(max_profit2 == expected_max_profit2);
94std::cout <<
"Maximum profit with "<< n2 <<
" inch road is "<< max_profit2
98std::array<int32_t, n3> price3 = {2, 9, 17, 23, 45};
99 constint64_t max_profit3 =
101 constint64_t expected_max_profit3 = 45;
102assert(max_profit3 == expected_max_profit3);
103std::cout <<
"Maximum profit with "<< n3 <<
" inch road is "<< max_profit3
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.
static void test()
Function to test above algorithm.
int main()
Main function.
Implementation of cutting a rod problem.
Dynamic Programming algorithms.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4