zoukankan      html  css  js  c++  java
  • 欧拉计划第15题题解

    Lattice paths

    Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.

    How many such routes are there through a 20×20 grid?

    网格路径

    从一个2×2方阵的左上角出发,只允许向右或向下移动,则恰好有6条通往右下角的路径。

    对于20×20方阵来说,这样的路径有多少条?

    解题思路

    动态规划。

    (f[i][j] = f[i-1][j] + f[i][j-1])

    实现代码如下:

    #include <bits/stdc++.h>
    using namespace std;
    long long f[21][21];
    int main() {
        for (int i = 1; i <= 20; i ++) {
            for (int j = 1; j <= 20; j ++) {
                if (i==1 || j==1) f[i][j] = 1;
                else f[i][j] = f[i-1][j] + f[i][j-1];
            }
        }
        cout << f[20][20] << endl;
        return 0;
    }
    

    答案为 (35345263800)

  • 相关阅读:
    Redis面试题
    redis基本操作
    pwd命令和cd命令
    ls命令详解
    Python时间操作所相关
    Nginx
    网络相关知识
    LeetCode 刷题记录(6-10题)
    绕过校园网Web认证
    Java相关知识
  • 原文地址:https://www.cnblogs.com/quanjun/p/12328013.html
Copyright © 2011-2022 走看看