A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/d6/d10/cut__rod_8cpp_source.html below:

TheAlgorithms/C++: dynamic_programming/cut_rod.cpp Source File

Go to the documentation of this file. 54 for

(

size_t

i = 1; i <= n; i++) {

56 for

(

size_t

j = 1; j <= i; j++) {

57

q = std::max(q, price[j - 1] + profit[i - j]);

61 const

int16_t ans = profit[n];

75

std::array<int32_t, n1> price1 = {1, 2, 4, 6, 8, 45, 21, 9};

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

84 const

int16_t n2 = 30;

85

std::array<int32_t, n2> price2 = {

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};

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

98

std::array<int32_t, n3> price3 = {2, 9, 17, 23, 45};

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

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