#include <iostream>
#include <vector>
#include <algorithm>
usingnamespace std;
vector<int> coins;
int checkchange(int left) {
vector<int> choices (coins.size());
if (left == 0)
return 0;
else {
int min;
for (int i=0;i<coins.size();i++) {
choices.at(i) = (1 + checkchange(left - coins.at(i)));
}
return min_element(choices.front(),choices.back());
}
}
int main() {
int N;
cin >> N;
for (int i=0;i<N;i++) {
int c,m,temp,change;
cin >> c >> m;
for (int j=0;j<c;j++) {
cin >> temp;
coins.push_back(temp);
}
for (int j=0;j<m;j++) {
cin >> temp;
change = checkchange(temp);
cout << change;
}
}
return 0;
}
I'm constantly getting the following error:
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/algorithm:62,
from burningcoins.cpp:3:
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_algo.h: In function ‘_FIter std::min_element(_FIter, _FIter) [with _FIter = int]’:
burningcoins.cpp:19: instantiated from here
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_algo.h:5998: error: invalid type argument of ‘unary *’
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_algo.h:5998: error: invalid type argument of ‘unary *
What am I doing wrong? I tried compiling with gcc and g++. Neither worked.