... HAVE U TRIED .... AT LEAST 3 TIMES ... OK U CAN SEE THIS ...

Tuesday, December 24, 2013

UVA-674 :: Coin Change

#include <iostream>
#include <bits/stdc++.h>
using namespace std ;
int coin[7]={1,5,10,25,50} , make ,dp[6][7500] ;
int func(int i , int p)
{
    if (i>=5)
    {
        if (p==0) return 1 ;
        else return 0 ;
    }
    if (dp[i][p] != -1) return dp[i][p] ;
    int w1=0 , w2=0 ;
    if (p-coin[i]>=0) w1=func(i,p-coin[i]) ;
    else w1=0 ;
    w2=func(i+1,p) ;
    dp[i][p]=w1+w2 ;
    return dp[i][p] ;
}

int main ()
{
      memset(dp,-1,sizeof (dp)) ;
    while (cin>>make)
    {
        cout<<func(0,make)<<endl ;
    }

    return 0 ;
}