You are viewing a single comment's thread. Return to all comments →
C#
private static Dictionary<(long, int), long> _memo = new Dictionary<(long, int), long>(); public static long getWays(int n, List<long> c) { return getWays(n, c, 0); } private static long getWays(long n, List<long> c, int i) { if (n == 0) return 1; if (n < 0) return 0; if (_memo.ContainsKey((n, i))) return _memo[(n, i)]; long ways = 0; for (int j = i; j < c.Count(); j++) { ways += getWays(n-c[j], c, j); } _memo.Add((n, i), ways); return ways; } }
Seems like cookies are disabled on this browser, please enable them to open this website
The Coin Change Problem
You are viewing a single comment's thread. Return to all comments →
C#