博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
动态规划之Unique Paths(java实现)
阅读量:4043 次
发布时间:2019-05-24

本文共 927 字,大约阅读时间需要 3 分钟。

1.问题描述:

A robot is located at the top-left corner of m X n grid.

The robot can only move either down or right an any point in time.The robot is try to reach the bottom-right corner of the grid.
How many possible unique paths are there?
在这里插入图片描述

2.java实现

package dynamic;/*Unique Paths  A robot is located at the top-left corner of m X n grid */public class UniquePaths {
public static int uniquePaths(int m,int n) {
int[][] f = new int[m][n]; int i, j; for (i = 0; i < m; i++) {
//row: top to bottom for (j = 0; j < n; j++) {
//column: left to right if (i == 0 || j == 0) {
f[i][j] = 1; } else {
f[i][j] = f[i - 1][j] + f[i][j - 1]; } } } return f[m - 1][n - 1]; } public static void main (String [] args) {
System.out.println(uniquePaths(7,3)); }}

转载地址:http://fyhdi.baihongyu.com/

你可能感兴趣的文章
WPF UI&控件免费开源库
查看>>
QT打开项目提示no valid settings file could be found
查看>>
Win10+VS+ESP32环境搭建
查看>>
Ubuntu+win10远程桌面
查看>>
flutter-实现圆角带边框的view(android无效)
查看>>
android 代码实现圆角
查看>>
flutter-解析json
查看>>
android中shader的使用
查看>>
java LinkedList与ArrayList迭代器遍历和for遍历对比
查看>>
drat中构造方法
查看>>
JavaScript的一些基础-数据类型
查看>>
JavaScript基础知识(2)
查看>>
转载一个webview开车指南以及实际项目中的使用
查看>>
android中对于非属性动画的整理
查看>>
一个简单的TabLayout的使用
查看>>
ReactNative使用Redux例子
查看>>
Promise的基本使用
查看>>
coursesa课程 Python 3 programming 统计文件有多少单词
查看>>
coursesa课程 Python 3 programming 输出每一行句子的第三个单词
查看>>
Returning a value from a function
查看>>