题解 | 二维斐波那契数列
二维斐波那契数列
https://www.nowcoder.com/practice/a1951ca9431646ff8f9bc6f6d24d1e0a?tpId=383&tqId=11211253&sourceUrl=%2Fexam%2Foj%3FquestionJobId%3D10%26subTabName%3Donline_coding_page
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
//#define debug
using ll = long long;
const ll M = 1e9 + 7;
void solve()
{
vector<vector<ll>> a(2000,vector<ll>(2000,0));
int x, y;
cin >> x >> y;
for (int i = 1; i <= x;i++)
{
for (int j = 1; j <= y;j++)
{
if(i==1||j==1)
{
a[i][j] = 1;
}
else
{
a[i][j] = (a[i - 1][j] + a[i][j - 1])%M;
}
}
}
cout << a[x][y];
return;
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n=1;
while(n--)
solve();
return 0;
}
查看22道真题和解析