C# 1904번 01타일
2022. 1. 22. 17:58ㆍ코딩테스트 문제 풀이/[백준] 동적 계획법1
728x90
반응형
코드 :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _3
{
class Program
{
static void Main(string[] args)
{
int N = Convert.ToInt32(Console.ReadLine());
int[] tileCount = new int[1000001];
tileCount[1] = 1;
tileCount[2] = 2;
for (int i = 3; i <= N; i++)
{
tileCount[i] = (tileCount[i - 1] + tileCount[i - 2])%15746;
}
Console.WriteLine(tileCount[N]);
}
}
}
문제 풀이 :
tilecount[]에 넣기 전에 15746으로 나누는 이유는 그렇게 하지 않을 시 값이 너무 커져서 제대로 들어가지 않기 때문이다.
728x90
반응형
'코딩테스트 문제 풀이 > [백준] 동적 계획법1' 카테고리의 다른 글
C# 1932번 정수 삼각형 (0) | 2022.01.22 |
---|---|
C# 1149번 RGB거리 (0) | 2022.01.22 |
C# 9461번 파도반 수열 (0) | 2022.01.22 |
C# 9184번 신나는 함수 실행 (0) | 2022.01.22 |
C# 1003번 피보나치 함수 (0) | 2022.01.22 |