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

What's wrong with my solution with #TEST 5?
Posted by wakemecn 26 Sep 2012 12:19
/*
 * Filename:      1079.c
 * Author:        Junwei Wang(wakemecn@gmail.com)
 * Last Modified: 2012-09-26 14:13
 * Description:
 *
 */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

long a[100001];
long max[10001];
long i;
long n;

long compute(long num)
{
    if (num % 2 == 0)
        return a[num / 2];
    return a[num / 2] + a[num / 2 + 1];
}

int main(void)
{
    a[0] = 0;
    a[1] = 1;

    max[0] = 0;
    max[1] = 1;

    for (i=2; i<=99999; i++) {
        a[i] = compute(i);
//        printf("a[%ld]=%ld\n", i, a[i]);

        if (a[i] > max[i-1])
            max[i] = a[i];
        else
            max[i] = max[i-1];
    }

    scanf("%ld", &n);
    if (n == 0)
        exit(0);
    do {
        printf("%ld\n", max[n]);
        scanf("%ld", &n);
    } while (n);
}