Sunday, 12 July 2015

AMZRCK

Standard

Amz Rock

Link to the question : AMZRCK 

HINT : 

A very nice problem of fibonacci numbers and dynamic programming. Dont know but I think can be done with minimal processing also.

SOURCE CODE :

#include <iostream>
using namespace std;
int main()
{
long long int a[45];
int t, x;
a[0] = 1;
a[1] = 2;
for(int i = 2; i < 45; i++)
a[i] = a[i-1] + a[i-2];
cin >> t;
for(int i = 0; i < t; i++)
{
cin >> x;
cout << a[x] << endl;
}
return 0;
}

0 comments:

Post a Comment