Skip to content

Instantly share code, notes, and snippets.

@tehp
Created December 12, 2017 18:38
Show Gist options
  • Save tehp/6a02b96e2cbe2f05c88a3d1562220541 to your computer and use it in GitHub Desktop.
Save tehp/6a02b96e2cbe2f05c88a3d1562220541 to your computer and use it in GitHub Desktop.
//
// main.cpp
// algoFinal
//
// Created by Mac Craig on 2017-12-12.
// Copyright © 2017 mcknzcrg. All rights reserved.
//
#include <iostream>
#include <algorithm>
using namespace std;
int algo2(int n, int v[]) {
int T[4][n];
for (int i = 0; i < n; i++) {
T[0][i] = 0;
}
for (int j = 0; j < 4; j++) {
for (int k = 0; k < n; k++ ) {
if (v[j] < n) {
T[j][k] = T[j-1][k];
} else {
T[j][k] = min(v[j] + T[j-1][j-v[j]], T[j-1][k]);
}
}
}
return T[4][n];
}
int main()
{
int v[4] = {1, 3, 4, 7};
cout << "result: " << algo2(6, v) << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment