Skip to content

Instantly share code, notes, and snippets.

@Abreto
Created October 22, 2013 14:29
Show Gist options
  • Save Abreto/7101702 to your computer and use it in GitHub Desktop.
Save Abreto/7101702 to your computer and use it in GitHub Desktop.
Wikioi - Problem 1039.
/* Wikioi - Proeblem 1039 . by Abreto. */
#include <stdio.h>
#define MAXN 200
#define MAXK 6
int f[MAXN+1][MAXN+1][MAXK+1] = {{{0}}};
int
dp(int i, int n, int k)
{
int j = 0;
int *ans = &(f[i][n][k]);
if(*ans)
return (*ans);
if( 1 == k )
if( i <= n )
return (*ans = 1);
else
return (*ans = 0);
for(j = i;j <= n/2;j++)
{
*ans += dp(j,n-j,k-1);
}
return (*ans);
}
int
main(void)
{
int N = 0, K = 0;
scanf("%d %d", &N, &K);
printf("%d\n", dp(1,N,K));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment