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

If you want to know how to solve this problem, look here! :-)
Posted by Veselin Kolev 13 Sep 2004 01:20
#include <iostream>

using namespace std;
unsigned nMax=0;
unsigned n[10];
unsigned solveAns[100000];
short Count=-1;

void Input()
     {unsigned nTec;
      cin>>nTec;
      while (nTec!=0)
            {Count++;
             n[Count]=nTec;
             if (nMax<nTec) nMax=nTec;
             cin>>nTec;
            }
     }

void Solve()
     {solveAns[0]=0;
      solveAns[1]=1;
      for (int i=2; i<=nMax; i++)
          {solveAns[i]=solveAns[i/2];
           i++;
           solveAns[i]=solveAns[i/2]+solveAns[(i/2)+1];
          }
     }

void Output()
     {unsigned Max;
      for (int i=0; i<=Count; i++)
          {Max=0;
           for (int j=0; j<=n[i]; j++)
              if (Max<solveAns[j])
                 Max=solveAns[j];
           cout<<Max<<"\n";
          }
     }

int main()
    {Input();
     Solve();
     Output();
     return 0;
    }