Dalyoung 2021. 6. 7. 22:16
반응형

 

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

 

반응형