psbook solutions

সমস্যা ও সমাধান বই - ১ এর উপর অনুশীলন ( Practice code for Problem and Solutions Book - 1 by Mahbubul Hasan )

View the Project on GitHub

Timus 1079 - Maximum

Commit Time 15 Oct 2017 14:44
#include <bits/stdc++.h>

#define MAX 99999

using namespace std;

int arr[MAX+5];

void cal() {
    arr[0] = 1;
    arr[1] = 1;
    for (int i = 2; i <= MAX; i++) {
        if(i&1) arr[i] = arr[i/2] + arr[i/2 + 1];
        else arr[i] = arr[i/2];
    }
    for (int i = 2; i <= MAX; i++) arr[i] = max(arr[i], arr[i-1]);
}

int main() {
    cal();
    int n;
    while(scanf("%d", &n) && n != 0) printf("%d\n", arr[n]);
}