package test; import java.util.*; public class Main{ public static int f(int n,int k, int goal){ if(goal==1) return n-k+1; if(n-k+1<goal) return 0; return f(n,k+1,goal)+f(n,k+1,goal-1); } public static void f1(int[][] res,int k,int goal,int n,int m) { for(int i=1;i<=n;i++) res[i][1]=n-i+1; for(int i=n;i>=1;i--) { for(int j=2;j<=m;j++) { if(n-i+1<j)res[i][j]=0; else res[i][j]=res[i+1][j]+res[i+1][j-1]; } } }
public static int f3(int m, int n){
if(n==m) return 1;
if(n==0) return 1;
return f(m-1,n) + f(m-1,n-1);
} public static void main(String[] args) { int n=1,m=1; System.out.println(f(n,1,m)); int[][] res=new int[n+1][m+1]; f1(res,1,3,n,m); System.out.println(res[1][m]); } }