-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from amsharma44/coin_change
Coin change
- Loading branch information
Showing
2 changed files
with
57 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.