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

Tuesday, December 24, 2013

UVA-357 :: Let Me Count The Ways

#include <iostream>
#include <bits/stdc++.h>
using namespace std ;
#define max 30010

int main ()
{
       long long int n, i ,x,j ,a[max] ,coin[50] ={0,1,5,10,25,50};

        while (cin>>n)
        {
            for (i=0 ; i<max ; i++) a[i]=0 ;
            a[0]=1 ;

            for (i=1 ; i<=5 ; i++)
            {
                x=coin[i] ;
                for (j=x ; j<=n ; j++)
                {
                    if (a[j]>=0)  a[j]=a[j]+a[j-x] ;
                }

            }   if(a[n]>1) printf ("There are %lld ways to produce %lld cents change.\n",a[n],n);

            else printf ("There is only 1 way to produce %lld cents change.\n",n) ;
        }

    return 0 ;
}