Skip to content

Instantly share code, notes, and snippets.

@PreciousNyasulu
Created February 9, 2023 07:56
Show Gist options
  • Save PreciousNyasulu/7255124e7e833301577b17b74cd568aa to your computer and use it in GitHub Desktop.
Save PreciousNyasulu/7255124e7e833301577b17b74cd568aa to your computer and use it in GitHub Desktop.
Problem #1
using System;
class Program
{
static int MaxNumOfAs(int numOfPresses)
{
if (numOfPresses <= 6)
{
return numOfPresses;
}
int[] maxNumOfAs = new int[numOfPresses + 1];
for (int i = 1; i <= 6; i++)
{
maxNumOfAs[i] = i;
}
for (int i = 7; i <= numOfPresses; i++)
{
for (int j = i - 3; j >= 1; j--)
{
maxNumOfAs[i] = Math.Max(maxNumOfAs[i], maxNumOfAs[j] * (i - j - 1));
}
}
return maxNumOfAs[numOfPresses];
}
static void Main(string[] args)
{
int numOfPresses = 2;
int maxA = MaxNumOfAs(numOfPresses);
Console.WriteLine(maxA);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment