Last active
August 29, 2015 14:17
-
-
Save ch-hristov/c48e0878aae8ecc0282c to your computer and use it in GitHub Desktop.
Minimum count of items which are equal to s
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
int main() | |
{ | |
int MAX = 9999999; | |
vector<int> c; | |
int cnt; | |
cin >> cnt; | |
for(int i = 0;i<cnt;i++){ | |
int j; | |
cin >> j; | |
c.push_back(j); | |
} | |
int s; | |
cin >> s; | |
int d[s+1]; | |
for(int i =0;i <=s;i++) | |
d[i]=MAX; | |
d[0]=0; | |
for(int j = 1;j <=s;j++){ | |
for(int i = 0;i < cnt;i++){ | |
if(c[i] <= j && d[j-c[i]]+1<d[j]){ | |
d[j]=d[j-c[i]]+1; | |
} | |
} | |
} | |
cout << d[s] << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment