fixed clang-tidy warnings

This commit is contained in:
Pardeep Bhatt
2020-09-24 12:22:40 +05:30
parent 4d211fc51b
commit 698396b019

View File

@@ -3,24 +3,30 @@ contains prices of all pieces of size smaller than n. Determine
the maximum value obtainable by cutting up the rod and selling
the pieces.*/
#include <array>
#include <climits>
#include <iostream>
using namespace std;
int cutrod(int p[], int n) {
int r[n + 1];
using std::cout;
template <size_t T>
int cutrod(const std::array<int, T> &p, int n) {
std::array<int, n + 1> r;
r[0] = 0;
for (int j = 0; j < n; j++) {
int q = INT_MIN;
for (int i = 0; i <= j; i++) {
q = max(q, p[i] + r[j - i]);
q = std::max(q, p[i] + r[j - i]);
}
r[j + 1] = q;
}
return r[n];
}
int main() {
int price[] = {1, 5, 8, 9, 10, 17, 17, 20, 24, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50};
std::array<int, 30> price = {1, 5, 8, 9, 10, 17, 17, 20, 24, 30,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50};
cout << cutrod(price, 30);
return 0;
}