Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

please add code to build 'dp' table #2

Closed
CuthbertJungle opened this issue Dec 23, 2016 · 1 comment
Closed

please add code to build 'dp' table #2

CuthbertJungle opened this issue Dec 23, 2016 · 1 comment

Comments

@CuthbertJungle
Copy link

Hi,

please could you provide the code to build the 3 dimensional 'dp' table.

thanks :-)

@HenryRLee
Copy link
Owner

Hi,

Here is the source code that I used for generating the 'dp' table.


static int dp[5][14][8];
static int choose[53][8];

int init(void)
{
	int i;
	int j;
	int k;
	int l;

	/* choose */
	memset(choose, 0, sizeof(choose));

	for (i=0; i<=52; i++)
	{
		choose[i][0] = 1;
		choose[i][1] = i;
		choose[i][i] = 1;
	}

	for (i=1; i<=52; i++)
	{
		for (j=2; j<=7 && j<=i; j++)
		{
			choose[i][j] = choose[i-1][j] + choose[i-1][j-1];
		}
	}

	/* quinary */
	memset(dp, 0, sizeof(dp));

	for (i=0; i<=7; i++)
	{
		if (i >= 5)
			dp[1][1][i] = 0;
		else
			dp[1][1][i] = 1;

		dp[1][0][i] = 0;
	}

	for (i=1; i<=13; i++)
	{
		dp[1][i][1] = i;
		dp[1][i][0] = 1;
	}

	for (i=2; i<=13; i++)
	{
		for (j=2; j<=7; j++)
		{
			int sum = 0;

			for (k=0; k<=4 && k<=j; k++)
			{
				sum += dp[1][i-1][j-k];
			}

			dp[1][i][j] = sum;
		}
	}

	for (l=2; l<=4; l++)
	{
		for (i=1; i<=13; i++)
		{
			for (j=0; j<=7; j++)
			{
				if (j >= l-1)
					dp[l][i][j] = dp[l-1][i][j] + dp[1][i][j-l+1];
				else
					dp[l][i][j] = dp[l-1][i][j];
			}
		}
	}

	return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants