Skip to content

Instantly share code, notes, and snippets.

@wsdookadr
Created August 18, 2011 21:31
Show Gist options
  • Select an option

  • Save wsdookadr/1155280 to your computer and use it in GitHub Desktop.

Select an option

Save wsdookadr/1155280 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#define MAXN 300
#define min(a,b) ( (a<b)?(a):(b) )
#define max(a,b) ( (a>b)?(a):(b) )
int solve(int n) {
int T[MAXN];
assert(n>=0);
memset(T,0,MAXN*sizeof(int));
int i,j,k;
int sol = -1;
T[0] = 0;
T[1] = 1;
/*for(k=2;k<=((int)floor(n/2))+1;k++) {*/
for(k=2;k<=n;k++) {
// compute T[k]
int Tmax = -1;
for(i=1;i<=k/2;i++) {
Tmax = max(
Tmax,
max(
T[i]*T[k-i],
i*(k-i)
)
);
};
T[k] = Tmax;
};
return T[n];
}
int main(char argc,char **argv) {
int n;
scanf("%d",&n);
printf("%d\n",solve(n));
return 0;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment