900 - Brick Wall Patterns

All about problems in Volume 9. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

mainul07
New poster
Posts: 8
Joined: Fri Oct 05, 2012 1:35 pm
Location: Chittagong
Contact:

Uva Problem 900

Post by mainul07 » Sat Oct 06, 2012 11:03 am

Code: Select all

#include<iostream>
using namespace std;
int main()
{
    long long int n,i,a[100000];
    while(cin>>n)
    {
        if(n==0)
        break;
        a[1]=1;
        a[2]=2;
        for(i=3;i<=n;i++)
        a[i]=a[i-1]+a[i-2];
        cout<<a[n]<<endl;
    }
    return 0;
}

It show time limit exceded please help me ... :wink:
Last edited by brianfry713 on Mon Nov 24, 2014 10:55 pm, edited 1 time in total.
Reason: Added code blocks
Mainul Hassan
Website:http://www.teronga.com/

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: Uva Problem 900

Post by brianfry713 » Sun Oct 07, 2012 7:33 pm

Precompute the results for n=1 through 50.
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 9 (900-999)”