Matrix find number of ways to reach the other corner
Page 1 of 1
Matrix find number of ways to reach the other corner
public static int findpath(int M, int N){
int[][] array=new int[M][N];
for(int i=0;i<M;i++)
array[i][0]=1;
for(int j=0;j<N;j++)
array[0][j]=1;
for(int p=1;p<M;p++){
for(int q=1;q<N;q++){
array[p][q]=array[p-1][q]+array[p][q-1];
}
}
return array[p-1][q-1];
}
int[][] array=new int[M][N];
for(int i=0;i<M;i++)
array[i][0]=1;
for(int j=0;j<N;j++)
array[0][j]=1;
for(int p=1;p<M;p++){
for(int q=1;q<N;q++){
array[p][q]=array[p-1][q]+array[p][q-1];
}
}
return array[p-1][q-1];
}
skyboard- Posts : 31
Join date : 2011-09-03
Similar topics
» Given a magic number sum, to find if there are two numbers whose sum equals to the number
» An array of integers, all appear twice except one, find this number.
» Find the number of inversions in an array
» In an array there is one element which repeats more than n/2 times...find the number in 0(n) time and 0(1) space
» Given a sorted array find all possible |ai - aj| where ai,aj belongs to Array A. n^2 is obvious. Find a solution in O(N).
» An array of integers, all appear twice except one, find this number.
» Find the number of inversions in an array
» In an array there is one element which repeats more than n/2 times...find the number in 0(n) time and 0(1) space
» Given a sorted array find all possible |ai - aj| where ai,aj belongs to Array A. n^2 is obvious. Find a solution in O(N).
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|