机器人走方格系列

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

posted @ 2016-10-07 14:35  pandaB  阅读(172)  评论(0编辑  收藏  举报