Skip to content

Instantly share code, notes, and snippets.

Created August 8, 2010 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/513932 to your computer and use it in GitHub Desktop.
Save anonymous/513932 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#define N 5
#define M 4
int main()
{
int dp[N + 1][M + 1] = {{0}};
dp[0][1] = 1;
int i, j, k;
for (i = 0; i < N; i++)
{
for (j = 1; j <= M; j++)
{
for (k = 1; k <= M; k++)
{
if (k != j)
dp[i + 1][j] += dp[i][k];
}
}
}
printf("%d\n", dp[N][1]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment