Professional Documents
Culture Documents
if (i == 1 || i == x || i == y) {
dp[i] = true;
}
else if (i < x) {
dp[i] = !dp[i - 1];
}
else if (i < y) {
dp[i] = !(dp[i - x] && dp[i - 1]);
}
else {
dp[i] = !(dp[i - x] && dp[i - y] && dp[i - 1]);
}
}
import java.util.*;
public class Solution {
public static int minDis(String s1, String s2, int m, int n, int dp[][]){
if(m == 0)
return n;
if(n == 0)
return m;
if(dp[m][n - 1] != -1)
{
m2 = dp[m][n - 1];
}
else
{
m2 = minDis(s1, s2, m, n - 1, dp);
}
if (dp[n][W] != -1)
return dp[n][W];
if (wt[n - 1] > W)
else
// Pick all coins one by one and update the table[] values
// after the index greater than or equal to the value of the
// picked coin
for(int i=0; i<m; i++)
for(int j=S[i]; j<=n; j++)
table[j] += table[j-S[i]];
return table[n];
}
// Write your code here
}
}
}
int max=0;
for(int i=1;i<m;i++){
for(int j=1;j<n;j++){
if(arr[i][j]==0){
dp[i][j]=1+Math.min(dp[i-1][j-1],Math.min(dp[i-1][j],dp[i][j-1]));
if(max<dp[i][j]){
max=dp[i][j];
}
}
// else{
// dp[i][j]=1;
// }
}
}
return max;
}
}
public class Solution {
}
}
int max=0;
for(int i=1;i<m;i++){
for(int j=1;j<n;j++){
if(arr[i][j]==0){
dp[i][j]=1+Math.min(dp[i-1][j-1],Math.min(dp[i-1][j],dp[i][j-1]));
if(max<dp[i][j]){
max=dp[i][j];
}
}
// else{
// dp[i][j]=1;
// }
}
}
return max;
}
}