-
[백준-9184] 신나는 함수 실행 - Java공부/백준 2022. 5. 4. 23:07728x90
코드
import java.util.*;public class back9184 {static int dp[][][]=new int[21][21][21];public static void main(String args[]){Scanner scanner=new Scanner(System.in);int num1=scanner.nextInt();int num2=scanner.nextInt();int num3=scanner.nextInt();while(num1!=-1||num2!=-1||num3!=-1){System.out.println("w("+num1+", "+num2+", "+num3+") = "+w(num1,num2,num3));num1=scanner.nextInt();num2=scanner.nextInt();num3=scanner.nextInt();}}public static int w(int num1, int num2, int num3){if(num1<=0||num2<=0||num3<=0){return 1;}if(num1>20||num2>20||num3>20){return dp[20][20][20]=w(20,20,20);}if(dp[num1][num2][num3]!=0){return dp[num1][num2][num3];}if(num1 < num2 && num2 < num3) {return dp[num1][num2][num3] = w(num1, num2, num3 - 1) + w(num1, num2 - 1, num3 - 1) - w(num1, num2 - 1, num3);}return dp[num1][num2][num3]= w(num1 - 1, num2, num3) + w(num1 - 1, num2 - 1, num3) + w(num1 - 1, num2, num3 - 1) - w(num1 - 1, num2 - 1, num3 - 1);}}728x90반응형'공부 > 백준' 카테고리의 다른 글
[백준-15649] N과 M(1) - Java (0) 2022.05.30 [백준-1463] 1로 만들기 - Java (0) 2022.05.06 [백준-9461] 파도반 수열 - Java (0) 2022.05.06 [백준-1904] 01타일 - Java (0) 2022.05.04 [백준-1003] 피보나치 함수 - Java (0) 2022.05.04