Skip to content

Commit

Permalink
Merge pull request #28 from amsharma44/coin_change
Browse files Browse the repository at this point in the history
Coin change
  • Loading branch information
ows-ali authored Oct 17, 2018
2 parents d1d240f + 5732efb commit e51a54d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 50 deletions.
57 changes: 57 additions & 0 deletions coin-change.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Diagnostics;

namespace ConsoleApplication
{

class Program
{
public static long[,] dp = new long[52, 252];

public static void Main(String[] args)
{
int[] l0 = Array.ConvertAll<string, int>(Console.ReadLine().Trim().Split(' '), e => int.Parse(e));
int[] coins = Array.ConvertAll<string, int>(Console.ReadLine().Trim().Split(' '), e => int.Parse(e));
int sum = l0[0];
int n = l0[1];
for(int i = 0; i < 52; i++)
{
for(int j = 0; j < 252; j++)
{
dp[i, j] = -1;
}
}

Console.WriteLine(calculate(coins, sum, n - 1, 0));
}

public static long calculate(int[] coins, int sum, int numCoin, int i)
{
if(sum == 0)
{
return 1;
}

if(sum < 0)
{
return 0;
}

if(i > numCoin)
{
return 0;
}

if(dp[i, sum] == -1)
{
dp[i, sum] = calculate(coins, sum, numCoin, i + 1) + calculate(coins, sum - coins[i], numCoin, i);
}

return dp[i, sum];
}
}
}
50 changes: 0 additions & 50 deletions string-reduction.cs

This file was deleted.

0 comments on commit e51a54d

Please sign in to comment.