private static HashSet<Integer> list = new HashSet<Integer>();     private static int getMinimumTimeCost(int n, int[][] area) {         int cols = area[0].length;         int price = 0;         int min = Integer.MAX_VALUE;         for(int col=0; col<cols; col++) {             if(col==5) System.out.println("hehe");             dfs(area, 0, col, price);         }         for(Integer data:list) {             if(data<min) {                 min = data;             }         }         return min;     }          private static void dfs( int[][] area, int row, int col, int price) {         if(col>=area[0].length) return;         if(row>=area.length) {list.add(price); return;}         int choose1=0, choose2=0;         choose1 = area[row+1][col];//向下的代价         if(col+1>=area[0].length) {             choose2 = 100000;//向右的代价         } else {             choose2 = area[row][col+1];//向右的代价         }         int price1    = price + choose1;         int price2 = price + choose2;         dfs(area, row+2, col, price1);         dfs(area, row, col+2, price2);     } } 没来的及提交,测试感觉结果还可以
点赞 2

相关推荐

已注销:bro不如吃顿疯狂星期四
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务