zoukankan      html  css  js  c++  java
  • 机器人走方格系列

    M * N的方格,一个机器人从左上走到右下,只能向右或向下走。有多少种不同的走法?由于方法数量可能很大,只需要输出Mod 10^9 + 7的结果。
    Input
    第1行,2个数M,N,中间用空格隔开。(2 <= m,n <= 1000)
    Output
    输出走法的数量。
    Input示例
    2 3
    Output示例
    3

    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    long long f[1005][1005];
    int n,m;
    void dp()
    {
        for(int i=1;i<=n;++i)
        {
            for(int j=1;j<=m;++j)
            {
                if(i==1&&j==1)f[i][j]=1;
                else f[i][j]=(f[i-1][j]+f[i][j-1])%1000000007;
            }    
        }
    }
    int main()
    {
        cin>>n>>m;
        dp();
        cout<<f[n][m];
        puts("");
        return 0;
    }
    View Code

    取模防爆int 不然开ll也没用 QAQ

  • 相关阅读:
    对拍
    311随笔
    精彩才刚刚开始
    做不下去了,就开心一下吧。
    情书
    论Sue这个人呐(=@__@=)
    P1113 杂务
    P1546 最短网络 Agri-Net
    P2009 跑步
    P2814 家谱
  • 原文地址:https://www.cnblogs.com/gc812/p/5935943.html
Copyright © 2011-2022 走看看