using System.Collections.Generic;
using System.Diagnostics;
namespace Shopper_item_budget_problem
public List<int> pairOfJeans;
public List<int> pairOfShoes;
public int dollarsBudget;
public static Shopper GenerateData()
Shopper shopper = new Shopper();
int thousand = (int)Math.Pow(10, 3);
int billion = (int)Math.Pow(10, 9);
Random rnd = new Random();
int araySize = rnd.Next(900, thousand + 1);
int dollarsBudget = rnd.Next(50000000, billion + 1);
List<int> pairOfJeans = new List<int>();
for (int i = 0; i < araySize; i++)
pairOfJeans.Add(rnd.Next(50000000, billion + 1));
araySize = rnd.Next(900, thousand + 1);
List<int> pairOfShoes = new List<int>();
for (int i = 0; i < araySize; i++)
pairOfShoes.Add(rnd.Next(50000000, billion + 1));
araySize = rnd.Next(900, thousand + 1);
List<int> tops = new List<int>();
for (int i = 0; i < araySize; i++)
tops.Add(rnd.Next(50000000, billion + 1));
araySize = rnd.Next(900, thousand + 1);
List<int> Skirts = new List<int>();
for (int i = 0; i < araySize; i++)
Skirts.Add(rnd.Next(50000000, billion + 1));
shopper.dollarsBudget = dollarsBudget;
shopper.pairOfJeans = pairOfJeans;
shopper.pairOfShoes = pairOfShoes;
static void Main(string[] args)
Console.WriteLine("Hello World!");
for (int i = 1; i <= 100; i++)
Stopwatch stopwatch = new Stopwatch();
Console.WriteLine("Attempt No. " + i);
Shopper shopper = GenerateData();
answer = NumberOfOptionsMemo1(shopper.pairOfJeans, shopper.pairOfShoes, shopper.tops, shopper.skirts, shopper.dollarsBudget);
Console.WriteLine("NumberOfOptionsMemo1: " + answer);
Console.WriteLine("Time elapsed: {0}", stopwatch.Elapsed);
public static long NumberOfOptions(List<int> pairOfJeans, List<int> pairOfShoes, List<int> tops, List<int> Skirts, int dollars)
long numberOfOptions = 0;
for (int a = 0; a < pairOfJeans.Count; a++)
for (int b = 0; b < pairOfShoes.Count; b++)
for (int c = 0; c < Skirts.Count; c++)
for (int d = 0; d < tops.Count; d++)
if (pairOfJeans[a] + pairOfShoes[b] + Skirts[c] + tops[d] <= dollars)
public static long NumberOfOptionsMemo1(List<int> pairOfJeans, List<int> pairOfShoes, List<int> tops, List<int> Skirts, int dollars)
long numberOfOptions = 0;
Dictionary<string, int> memoizationCD = new Dictionary<string, int>();
Dictionary<string, int> memoizationAB = new Dictionary<string, int>();
int numberOfItemsRemove = 0;
for (int i = 0; i < tops.Count; i++)
numberOfItemsRemove = tops.Count - (i + 1);
tops.RemoveRange(cutAt + 1, numberOfItemsRemove);
for (int i = 0; i < Skirts.Count; i++)
if (Skirts[i] >= dollars)
numberOfItemsRemove = Skirts.Count - (i + 1);
Skirts.RemoveRange(cutAt + 1, numberOfItemsRemove);
for (int i = 0; i < pairOfShoes.Count; i++)
if (pairOfShoes[i] >= dollars)
numberOfItemsRemove = pairOfShoes.Count - (i + 1);
pairOfShoes.RemoveRange(cutAt + 1, numberOfItemsRemove);
for (int i = 0; i < pairOfJeans.Count; i++)
if (pairOfJeans[i] >= dollars)
numberOfItemsRemove = pairOfJeans.Count - (i + 1);
pairOfJeans.RemoveRange(cutAt + 1, numberOfItemsRemove);
for (int c = 0; c < Skirts.Count; c++)
for (int d = 0; d < tops.Count; d++)
if (Skirts[c] + tops[d] < dollars)
memoizationCD["c" + c + "d" + d] = Skirts[c] + tops[d];
for (int a = 0; a < pairOfJeans.Count; a++)
for (int b = 0; b < pairOfShoes.Count; b++)
if (pairOfJeans[a] + pairOfShoes[b] < dollars)
memoizationAB["a" + a + "b" + b] = pairOfJeans[a] + pairOfShoes[b];
Console.WriteLine("memoizationCD Count: " + memoizationCD.Count);
Console.WriteLine("memoizationAB Count: " + memoizationAB.Count);
foreach (var outerPair in memoizationAB)
foreach (var innerPair in memoizationCD)
if (innerPair.Value + outerPair.Value <= dollars)