IT 정보/알고리즘(백준, BOJ)

[백준-BOJ] 9461

Dalyoung 2021. 6. 7. 22:16
728x90

 

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		Main m = new Main();
		m.doit();
	}
	
	
	long[] t = new long[101];
	public void doit() throws FileNotFoundException{
		//System.setIn(new FileInputStream("input.txt"));
		Scanner sc = new Scanner(System.in);
		t[1] = 1;
		t[2] = 1;
		t[3] = 1;
		t[4] = 2;
		t[5] = 2;
		
		int T = sc.nextInt();
		int last = 6;
		for(int c = 0; c < T; c++){
			int n = sc.nextInt();
			if(t[n] != 0){
				System.out.println(t[n]);
			}else {
				for(int i = last; i <= n; i++){
					t[i] = t[i - 1] + t[i - 5];
				}
				System.out.println(t[n]);
				last = n;
			}
		}
	}
	
}

https://www.acmicpc.net/problem/9461

 

9461번: 파도반 수열

오른쪽 그림과 같이 삼각형이 나선 모양으로 놓여져 있다. 첫 삼각형은 정삼각형으로 변의 길이는 1이다. 그 다음에는 다음과 같은 과정으로 정삼각형을 계속 추가한다. 나선에서 가장 긴 변의

www.acmicpc.net

 

728x90
반응형

'IT 정보 > 알고리즘(백준, BOJ)' 카테고리의 다른 글

[백준-BOJ] 9095  (0) 2021.05.10
[백준-BOJ] 9084  (0) 2021.05.10
[백준-BOJ] 9012  (0) 2021.05.10
[백준-BOJ] 8895  (0) 2021.04.07
[백준-BOJ] 7578  (0) 2021.04.07