Advertisement
BotByte

dp_coins_tc_2.cpp

May 13th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. /* Coin Change - Version I */
  2. /* Author : M. A. Rafsan Mazumder */
  3.  
  4. #include <bits/stdc++.h>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     int n;
  11.     scanf("%d", &n);
  12.     int arr[n];
  13.     for(int i=0; i<n; i++) scanf("%d", &arr[i]);
  14.     int tot;
  15.     scanf("%d", &tot);
  16.     int res[tot+1];
  17.     for(int i=1; i<=tot; i++) res[i] = INT_MAX;
  18.     res[0] = 0; //Important
  19.     for(int i=1; i<=tot; i++){
  20.         for(int j=0; j<n; j++){
  21.             if(i - arr[j] >= 0){
  22.                 if(res[i-arr[j]] + 1 < res[i]) res[i] = res[i-arr[j]] + 1;
  23.             }
  24.         }
  25.     }
  26.     cout << res[tot];
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement