ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1079. Maximum

MY AC in C
Posted by khaled_buet 3 Nov 2008 18:11
#include <stdio.h>

int n,x;
int a[10];
int i,t;

int _max(int s1,int s2,int x)
{
if (x==n)
return s1+s2;
else {
int t1,t2;
if (x*2-1<=n)
t1 = _max(s1,s2+s1,x*2-1);
else
t1 = 0;
if (x*2+1<=n)
t2 = _max(s1+s2,s2,x*2+1);
else
t2 = 0;
if ((t1==t2)&&(t2==0))
return s1+s2;
else
return t1>t2?t1:t2;
}
}

int main()
{
scanf("%d",&n);
i = 0;
while (n){
if (n==2)
a[i] = 1;
else
if (n==1)
a[i] = 1;
else
if (n==0)
a[i] = 0;
else
a[i] = _max(1,1,3);
scanf("%d",&n);
i++;
}
for (n = 0;n<i;n++)
printf("%d\n",a[n]);

return 0;
}