## Algorithm Game-Unique Paths 原

Wayen007

Unique Paths:

•  A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).
•  The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).
•  How many possible unique paths are there?

C# codes

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UniquePaths
{
class UniquePaths
{
static void Main(string[] args)
{
Console.Write("Please input m and n values for Array, the row is m, the column is n\n");
string[] nums = str.Split(new string[] { " " }, StringSplitOptions.None);
int m = Convert.ToInt32(nums[0]);
int n = Convert.ToInt32(nums[1]);

// Initialization an array
Console.Write("m={0}, n={1}\n", m, n);
if (m == 0 || n == 0)
{
Console.Write("Please input two valid numbers,m:{0} and n:{1} must be more than 0.\n", m, n);
}
Int64[,] array = new Int64[m, n];

// When the row or column is 0, the only one way to arrive every form,so we set 1 for them.
for (int i = 1; i < m; i++)
{
array[i, 0] = 1;
}
for (int j = 1; j < n; j++)
{
array[0, j] = 1;
}

// "-2" stand for "Start"
array[0, 0] = -2;
// "-1" stand for "Finish"
array[m - 1, n - 1] = -1;

// Before changing data, we can check the array values.
// If the value is 0, it stand for "Never Arriving". Otherwise, it stand for ways to arrive here.
Console.Write("Verify and print all of this array data:\n\n");
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
Console.Write("  " + array[i, j]);
}
Console.Write("\n");
}

bool key;
// If the row or column is 1,there is only one way to reach "Finish";
if (m == 1 || n == 1)
{
array[m - 1, n - 1] = 1;
key = false;
}
else
{
key = true;
}
while (key)
{
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
// Judge this process whether it will continue to run or not.
if (array[i, j] != -1)
{
key = true;
}
else
{
key = false;

}

// Skip row=0 or column=0
//if(array[i,j]==1|| array[i, j] ==-2)
if (i == 0 || j == 0)
{
continue;
}
else
{
array[i, j] = array[i - 1, j] + array[i, j - 1];
}
}
}
}

Console.Write("After running this programme and get result:\n");
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
Console.Write("  " + array[i, j]);
}
Console.Write("\n");
}
Console.Write("There are {0} ways from 'Start' to 'Finish'.\n\n", array[m - 1, n - 1]);
}
}
}

Results:

### Wayen007

QA/测试工程师

qq_32690999
2018/02/09
0
0

■实施上的注意事项 Notes on Implementation 现在您了解了基本的方法，当你编写自己的程序时，有一些额外的事情要考虑。下面给出我用C ++和Blitz Basic编写的程序，用其他语言也同样有效。 ...

2015/06/11
0
0
Leetcode 62. Unique Paths

s360564346
2016/12/15
12
0
Python一课一练（利用session来保存用户输入）

fantasiter
2016/12/28
12
0

2016/12/16
1
0

jenkins 配置

1. ssh-keygen -t rsa 2. 配置 GitLab 用户 创建一个用户或选择一个已有用户，用来让 Jenkins 和 GitLab API 交互。这个用户将需要是全局的管理员或添加进每个组／工程，并作为成员。需要开发...

14分钟前
1
0

21分钟前
1
0
Linux命令参数解析

Linux命令参数 通过一个例子来理解什么是Linux命令参数。以Linux中常用的删除命令“rm”为例，输入“rm --help”可以看到如下信息，其中红色框内的就是命令参数。经常使用Linux对命令参数应该...

RongJinhui0
24分钟前
1
0

29分钟前
1
0

32分钟前
2
0