Created
June 28, 2021 05:06
-
-
Save dalcon10028/5a9b5c41ea0f11105d7f2ec7115f4330 to your computer and use it in GitHub Desktop.
sssa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company; | |
import java.io.*; | |
import java.util.*; | |
public class Main { | |
static int[][] memo = new int[41][2]; | |
public static void main(String[] args) throws IOException { | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
StringBuilder sb = new StringBuilder(); | |
int t = Integer.parseInt(br.readLine()); | |
while (t-- > 0) { | |
int n = Integer.parseInt(br.readLine()); | |
memo[0][0] = 1; memo[0][1] = 0; | |
memo[1][0] = 0; memo[1][1] = 1; | |
if (memo[n][0] != 0) { | |
sb.append(memo[n][0] + " " + memo[n][1] + "\n"); | |
continue; | |
} | |
for (int i = 2; i <= n; i++) { | |
memo[i][0] = memo[i-1][0] + memo[i-2][0]; | |
memo[i][1] = memo[i-1][1] + memo[i-2][1]; | |
} | |
sb.append(memo[n][0] + " " + memo[n][1] + "\n"); | |
} | |
System.out.print(sb); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment