mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
Update cut_rod.cpp
This commit is contained in:
parent
8c4d4c0dba
commit
b2583bb9df
@ -71,11 +71,11 @@ int maxProfitByCuttingRod(const std::array<int, T> &price, const uint64_t &n) {
|
|||||||
static void test() {
|
static void test() {
|
||||||
// Test 1
|
// Test 1
|
||||||
const int16_t n1 = 8; // size of rod
|
const int16_t n1 = 8; // size of rod
|
||||||
std::array<int32_t, n1> price1 = {1,2,4,6,8,45,21,9}; // price array
|
std::array<int32_t, n1> price1 = {1,2,4,6,8,45,21,9}; // price array
|
||||||
const int64_t max_profit1 =
|
const int64_t max_profit1 =
|
||||||
dynamic_programming::cut_rod::maxProfitByCuttingRod(price1, n1);
|
dynamic_programming::cut_rod::maxProfitByCuttingRod(price1, n1);
|
||||||
const int64_t expected_max_profit1 = 47;
|
const int64_t expected_max_profit1 = 47;
|
||||||
assert(max_profit1 == expected_max_profit1);
|
assert(max_profit1 == expected_max_profit1);
|
||||||
std::cout << "Maximum profit with " << n1 << " inch road is " << max_profit1
|
std::cout << "Maximum profit with " << n1 << " inch road is " << max_profit1
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
@ -86,10 +86,10 @@ static void test() {
|
|||||||
31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
||||||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50};
|
41, 42, 43, 44, 45, 46, 47, 48, 49, 50};
|
||||||
|
|
||||||
const int64_t max_profit2=
|
const int64_t max_profit2=
|
||||||
dynamic_programming::cut_rod::maxProfitByCuttingRod(price2, n2);
|
dynamic_programming::cut_rod::maxProfitByCuttingRod(price2, n2);
|
||||||
const int32_t expected_max_profit2 = 90;
|
const int32_t expected_max_profit2 = 90;
|
||||||
assert(max_profit2 == expected_max_profit2);
|
assert(max_profit2 == expected_max_profit2);
|
||||||
std::cout << "Maximum profit with " << n2 << " inch road is " << max_profit2
|
std::cout << "Maximum profit with " << n2 << " inch road is " << max_profit2
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user