package countmethod;
import java.util.Scanner;
public class StepToNm {
int count;
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
System.out.println(“in n:”);
int n = sc.nextInt();
System.out.println(“in m:”);
int m = sc.nextInt();
StepToNm stepItem=new StepToNm();
stepItem.step(1,n,0,m);
System.out.println(stepItem.count);
}
public void step(int currentRow,int destRow,int currentColumn,int destColumn)
{
if(currentRow>destRow) {
if(currentColumn==destColumn) this.count ;
return;
}
for(int j=1;j<=destColumn;j) {
if(j % 2 == 0 && currentRow % 2 == 0) {
return;
}
step(currentRow+1,destRow,j,destColumn);
}
}
}
import java.util.Scanner;
public class StepToNm {
int count;
Integer counts[][];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(“in n:”);
int n = sc.nextInt();
System.out.println(“in m:”);
int m = sc.nextInt();
StepToNm stepItem = new StepToNm();
stepItem.counts=new Integer[n+1][m+1];
stepItem.step(1,1,stepItem.counts);
System.out.println(stepItem.counts[n][m]);
}
// / public void step(int currentRow, int destRow, int currentColumn, int destColumn) {
// if (currentRow > destRow) {
// if (currentColumn == destColumn) this.count;
// return;
// }
// for (; currentColumn <= destColumn; currentColumn) {
// if (currentColumn % 2 == 0 && currentRow % 2 == 0) {
// return;
// }
// step(currentRow + 1, destRow, currentColumn, destColumn);
// }
// }/
public int step(int currentRow, int currentColumn, Integer [][]columns) {
if (currentRow > columns.length-1) {
if (currentColumn == columns[0].length-1) return 1;
return 0;
}
if (currentColumn>columns[0].length-1) {
return 0;
}
for (; currentColumn <= columns[0].length-1; currentColumn++) {
if (currentColumn % 2 == 0 && currentRow % 2 == 0) {
columns[currentRow][currentColumn]=0;
return 0;
}
if (currentRow!=columns.length-1 && columns[currentRow+1][currentColumn]!=null) {
columns[currentRow][currentColumn]=
columns[currentRow+1][currentColumn]+step(currentRow,currentColumn+1,columns);
}else {
columns[currentRow][currentColumn] =
step(currentRow, currentColumn + 1, columns) + step(currentRow+1, currentColumn, columns);
}
}