using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Fibo
{
class Program
{
private const int MAX = 512;
private static decimal[] memo;
static void Main(string[] args)
{
memo = new decimal[MAX];
for (int i = 0; i < MAX; ++i)
{
memo[i] = 0;
}
int input = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(fibo(input));
}
static decimal fibo(int idx)
{
if (idx == 0)
{
return 0;
}
else if (idx == 1)
{
return 1;
}
if (memo[idx] > 0)
{
return memo[idx];
}
else
{
memo[idx] = fibo(idx - 2) + fibo(idx - 1);
return memo[idx];
}
}
}
}
c# 피보나치 구현
2014. 5. 7. 14:31