[2748] C# 풀이 피보나치 수 2
2019. 11. 7. 18:47ㆍIT#개발/알고리즘
자꾸 런타임 에러가 나서 뭐지 했다가.. 자료형..
using System;
namespace Programs
{
class Program
{
private static long[] s = new long[100];
static void Main(string[] args)
{
var r = long.Parse(Console.ReadLine());
Console.WriteLine(Fibonacci(r));
}
public static long Fibonacci(long t)
{
if (t == 1) return 1;
if (t == 2) return 1;
if (s[t] != 0) return s[t];
return s[t] = Fibonacci(t - 1) + Fibonacci(t - 2);
}
}
}
'IT#개발 > 알고리즘' 카테고리의 다른 글
c# 기수정렬 (radix sort) (0) | 2019.10.16 |
---|---|
[2667] c# 풀이 단지번호 붙이기 - BFS (0) | 2019.10.12 |
[2667] c# 풀이 단지번호 붙이기 - DFS (0) | 2019.10.04 |