<gouthampradhan>dynamic_programming_NonNegativeIntegersWithoutConsecutiveOnes_1.java
public int findIntegers(int num) {
    int msbIndex = 0;
    for (int i = 0; i < 31; i++) {
      if (((1 << i) & num) > 0) {
        msbIndex = i;
      }
    }
    int[][] DP1 = new int[2][msbIndex + 1]; 
    int[][] DP2 = new int[2][msbIndex + 2]; 
    for (int i = msbIndex; i >= 0; i--) {
      if (i == msbIndex) {
        DP1[0][msbIndex] = 1;
        DP1[1][msbIndex] = 1;
      } else {
        DP1[0][i] = DP1[0][i + 1] + DP1[1][i + 1];
        DP1[1][i] = DP1[0][i + 1];
      }
    }
    int[] bits = new int[msbIndex + 1];
    boolean bitFlipped = false;
    for (int i = msbIndex, j = 0; i >= 0; i--, j++) {
      if (j == 0) {
        bits[j] = 1;
      } else {
        if (bitFlipped) {
          bits[j] = bits[j - 1] == 0 ? 1 : 0;
        } else {
          if (((1 << i) & num) > 0) {
            if (bits[j - 1] > 0) {
              bits[j] = 0;
              bitFlipped = true;
            } else bits[j] = 1;
          }
        }
      }
    }
    DP2[0][msbIndex + 1] = 1;
    for (int i = bits.length - 1; i >= 0; i--) {
      if (bits[i] == 0) {
        DP2[0][i] = DP2[0][i + 1] + DP2[1][i + 1];
        if (bits[i - 1] == 0) {
          DP2[1][i] = (i == bits.length - 1) ? 1 : DP1[0][i + 1];
        }
      } else {
        DP2[1][i] = DP2[0][i + 1];
      }
    }
    return (DP1[0][0] + DP1[1][0]) - (DP2[0][0] + DP2[1][0]) + 1;
  }
public int sample_funcname ( int var_0 ) {
  int var_2 = 0 ;
  for ( int var_3 = 0 ;
  var_3 < 31 ;
  var_3 ++ ) {
    if ( ( ( 1 << var_3 ) & var_0 ) > 0 ) {
      var_2 = var_3 ;
    }
  }
  int [ ] [ ] var_7 = new int [ 2 ] [ var_2 + 1 ] ;
  int [ ] [ ] var_8 = new int [ 2 ] [ var_2 + 2 ] ;
  for ( int var_3 = var_2 ;
  var_3 >= 0 ;
  var_3 -- ) {
    if ( var_3 == var_2 ) {
      var_7 [ 0 ] [ var_2 ] = 1 ;
      var_7 [ 1 ] [ var_2 ] = 1 ;
    }
    else {
      var_7 [ 0 ] [ var_3 ] = var_7 [ 0 ] [ var_3 + 1 ] + var_7 [ 1 ] [ var_3 + 1 ] ;
      var_7 [ 1 ] [ var_3 ] = var_7 [ 0 ] [ var_3 + 1 ] ;
    }
  }
  int [ ] var_9 = new int [ var_2 + 1 ] ;
  boolean var_12 = false ;
  for ( int var_3 = var_2 , var_11 = 0 ;
  var_3 >= 0 ;
  var_3 -- , var_11 ++ ) {
    if ( var_11 == 0 ) {
      var_9 [ var_11 ] = 1 ;
    }
    else {
      if ( var_12 ) {
        var_9 [ var_11 ] = var_9 [ var_11 - 1 ] == 0 ? 1 : 0 ;
      }
      else {
        if ( ( ( 1 << var_3 ) & var_0 ) > 0 ) {
          if ( var_9 [ var_11 - 1 ] > 0 ) {
            var_9 [ var_11 ] = 0 ;
            var_12 = true ;
          }
          else var_9 [ var_11 ] = 1 ;
        }
      }
    }
  }
  var_8 [ 0 ] [ var_2 + 1 ] = 1 ;
  for ( int var_3 = var_9 . length - 1 ;
  var_3 >= 0 ;
  var_3 -- ) {
    if ( var_9 [ var_3 ] == 0 ) {
      var_8 [ 0 ] [ var_3 ] = var_8 [ 0 ] [ var_3 + 1 ] + var_8 [ 1 ] [ var_3 + 1 ] ;
      if ( var_9 [ var_3 - 1 ] == 0 ) {
        var_8 [ 1 ] [ var_3 ] = ( var_3 == var_9 . length - 1 ) ? 1 : var_7 [ 0 ] [ var_3 + 1 ] ;
      }
    }
    else {
      var_8 [ 1 ] [ var_3 ] = var_8 [ 0 ] [ var_3 + 1 ] ;
    }
  }
  return ( var_7 [ 0 ] [ 0 ] + var_7 [ 1 ] [ 0 ] ) - ( var_8 [ 0 ] [ 0 ] + var_8 [ 1 ] [ 0 ] ) + 1 ;
}
