upload MoztzkinNumber.java

This commit is contained in:
Siwat Sirichai 2020-11-03 11:06:47 +07:00
parent 43dea6e6e5
commit bfd2e95a10
2 changed files with 16 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,16 @@
public class MotzkinNumber {
public static void main(String[] args) {
for(int i=0;i<=20;i++)System.out.format("%d:%d\n",i,M(i));
}
public static int M(int n) {
if(n==0 || n==1)
return 1;
int temp = 0;
for(int i = 0;i<=n-2;i++)temp+=M(i)*M(n-2-i);
return M(n-1)+temp;
}
}