Project Euler - Problem 15
来源:互联网 发布:js div删除classname 编辑:程序博客网 时间:2024/04/30 02:13
Starting in the top left corner of a 22 grid, there are 6 routes (without backtracking) to the bottom right corner.
How many routes are there through a 2020 grid?
解法一:
当前点到目标点的路径数=右边点到目标点的路径数 + 下边点到目标点的路径数
最右边或者最下边的一排,只能沿着目标方向垂直或者水平移动,因此路径为1。
static void HowManySteps(){ long[,] matrix = new long[21,21]; for (int i = 0; i <= 20; i++) { matrix[20, i] = 1; matrix[i, 20] = 1; } for (int i = 19; i >= 0; i--) { for (int j = 19; j >= 0; j--) { matrix[i, j] = matrix[i + 1, j] + matrix[i, j + 1]; } } Console.WriteLine(matrix[0, 0]);}
解法二:
这是离散数学中的非降路径问题~~
可以将问题抽象为:从点(0, 0)运动到(m, n),只能朝右或者朝下运动,每次运动1步。相当于在m+n次的运动当中,选取m次来进行向右的运动,则剩下的n次就是向下的运动。
运用排列组合的数学只是,可以得出H(0, 0) = C(m+n, m) = C(m+n, n) = 40! / (20! * 20!)
static double JieChen(int n){ if (n == 1) return 1; else return JieChen(n - 1) * n;}static void Main(string[] args){ double mPn = JieChen(40); double m = JieChen(20); double res = mPn / m / m; Console.WriteLine(res);}
- Project Euler Problem 15
- Project Euler - Problem 15
- Project Euler problem 15
- project euler Problem 15
- project euler problem 15
- Project Euler:Problem 15 Lattice paths
- Project Euler Problem 15 Lattice paths
- Euler Project Problem 6
- project euler problem 11
- Project Euler Problem 81
- Project Euler Problem 60
- Project Euler Problem 59
- Project Euler Problem 58
- Project Euler Problem 57
- Project Euler Problem 16
- Project Euler Problem 30
- Project Euler Problem 31
- Project Euler Problem 32
- Win7下tomcat拒绝访问 Unable to open the service 'Tomcat7'
- (精)hdoj 2544(最短路,地杰斯特拉算法)(无向图)
- 网络中心招聘 我等来了我想要的
- Project Euler - Problem 13
- Project Euler – Problem 14
- Project Euler - Problem 15
- Project Euler – Problem 16
- 嵌入式LINUX开发入门
- Project Euler – Problem 17
- 一日一点RakNet(40)--Lobby2Client-PS3
- Project Euler – Problem 18
- Project Euler – Problem 19
- 认识.Net
- 多态总结