日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java滑雪,AcWing 901. 滑雪-java

發(fā)布時(shí)間:2023/12/8 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java滑雪,AcWing 901. 滑雪-java 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

import java.io.*;

import java.util.Arrays;

class Main {

static int N = 310;

//存儲高度

static int r, c;

static int[][] h = new int[N][N];

//f存儲某點(diǎn)開始下滑的最大長度

static int[][] f = new int[N][N];

//是否已確定最大長度

static boolean[][] flag = new boolean[N][N];

//最大長度

static int res;

static int[] mx = {-1,1,0,0};

static int[] my = {0,0,-1,1};

static boolean check(int x, int y) {

return x < r && y < c && x >= 0 && y >= 0;

}

static void dfs(int x, int y) {

int height = h[x][y];

f[x][y] = 1;

flag[x][y] = true;

for (int i = 0; i < 4; i++) {

int nx = x + mx[i];

int ny = y + my[i];

if (check(nx, ny) && h[x][y] > h[nx][ny]) {

//如果未確定最長滑行距離,進(jìn)入搜索

if (!flag[nx][ny]) dfs(nx, ny);

f[x][y] = Math.max(f[x][y], f[nx][ny] + 1);

}

}

res = Math.max(res, f[x][y]);

}

public static void main(String[] args) throws IOException {

InputStreamReader isr = new InputStreamReader(System.in);

BufferedReader in = new BufferedReader(isr);

String[] strs = in.readLine().split(" ");

r = Integer.parseInt(strs[0]);

c = Integer.parseInt(strs[1]);

//r行c列

for (int i = 0; i < r; i++) {

strs = in.readLine().split(" ");

for (int j = 0; j < c; j++) h[i][j] = Integer.parseInt(strs[j]);

}

for (int i = 0; i < r; i++)

for (int j = 0; j < c; j++) {

if (!flag[i][j]) {

dfs(i,j);

}

}

System.out.println(res);

}

}

總結(jié)

以上是生活随笔為你收集整理的java滑雪,AcWing 901. 滑雪-java的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。