Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <climits>
- #include <algorithm>
- #include <vector>
- #include <stack>
- #include <queue>
- #include <cmath>
- using namespace std;
- int main() {
- int coins [] = {2,3,4,23};
- int max =999;
- int M[8];
- M[0]=0;
- for(int i=1; i<8; i++)
- M[i] = 9999;
- int track[8];
- track[0]=0;
- for(int i=0; i<4; i++){
- for(int j=1; j<=7; j++){
- if(j>=coins[i]){
- if(1+M[j-coins[i]]< M[j]){
- M[j] = 1+M[j-coins[i]];
- track[j] = coins[i];
- }
- // M[j] = min(1+M[j-coins[i]],M[j]);
- }
- }
- }
- for(int i=1; i<8; i++)
- cout<<M[i]<<" ";
- cout<<endl;
- for(int i=0; i<8; i++)
- cout<<i<<" : "<<track[i]<<endl;
- cout<<endl;
- int end =7;
- while(end !=0){
- cout<<track[end]<<" ";
- end -=track[end];
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment