Wednesday, August 24, 2016

UVa 900 Brick Wall Patterns

#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
 ll a[100],i,n;

 
 while(cin>>n)
 {
  if(n==0) break;
  memset(a,0,sizeof(a));
    a[1]=1;
  a[2]=2;
  for(i=3; i<=n; i++)
  {
   a[i]= a[i-1]+a[i-2];
  }
  
  cout<<a[n]<<endl;
 }
}

No comments:

Post a Comment

Thank you for commenting. Please wait for response :)