题解 | 二维斐波那契数列

二维斐波那契数列

https://www.nowcoder.com/practice/a1951ca9431646ff8f9bc6f6d24d1e0a

#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int n,m;cin>>n>>m;
    vector<vector<long long>> a(n+1,vector<long long>(m+1,1));
    for(int y=1;y<=n;y++)
    {
        for(int x=1;x<=m;x++)
        {
            if(x==1&&y==1)continue;
            else if(y==1)a[y][x]=1;
            else if(x==1)a[y][x]=1;
            else a[y][x]=(a[y-1][x]+a[y][x-1])%(1000000007);        }
    }
    cout<<a[n][m];
    return 0;
}

用x,y来循环便于理解,这里上交了几次才看到题目要求对10E+7取模,总之做题要细心。

全部评论

相关推荐

xtu大迫杰:偶遇校友,祝校友offer打牌
点赞 评论 收藏
分享
二十岁的编程男神王大...:读博吧兄弟,你这绩点太好了,何必转码,另外哈哈哈真见到有括号标出来985的,这个不标注也知道吧
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务