on
b9461_파도반수열
b9461_파도반수열
package com.hotfive.workbook.b9461_파도반수열; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { // 삼각형 갯수가 N개일 때 변의 길이는? BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int T = Integer.parseInt(br.readLine()); for (int t = 0; t < T; t++) { int N = Integer.parseInt(br.readLine()); long [] p = new long[101]; // 존재하는 변의 길이 // 갯수 p[1] = 1; p[2] = 1; p[3] = 1; for (int i = 4; i <= 100; i++) { p[i] = p[i - 3] + p[i - 2]; // System.out.println("p"+i+":"+p[i]); } System.out.println(p[N]); } } }
qp
변의 길이로 점화식을 찾으려고 했지만 문제에 적혀있는 순열대로
1, 1, 1, 2, 2, 3, 4, 5, 7, 9
(갯수에 따른 변의 길이로)점화식 하니까 금방됐다
[i] = p[i - 3] + p[i - 2];
from http://elevensix.tistory.com/74 by ccl(A) rewrite - 2021-09-15 03:01:34