Untitled

 avatar
user_0112079941
c_cpp
2 years ago
763 B
2
Indexable
Never
#include <iostream>
#include <iomanip>
#include <fstream>

constexpr int mod = 1000000000 + 7;

int n;
int m;
int** dp;

inline int plus_m(int a, int b)
{
	return (a % mod + b % mod) % mod;
}

using namespace std;

void pprint()
{
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
			cout << setw(3) << dp[i][j] << " ";
		cout << endl;
	}
}

int main()
{
	ifstream fin("input.txt");
	ofstream fout("output.txt");
	fin >> n >> m;
	dp = new int* [n];
	for (int i = 0; i < n; i++)
		dp[i] = new int[m];
	for(int i = 0; i < n; i++)
		dp[i][0] = 1;

	for(int j = 0; j < m; j++)
		dp[n-1][j] = 1;
	for (int j = 1; j < m; j++)
		for (int i = n - 2; i >= 0; i--)
			dp[i][j] = plus_m(dp[i + 1][j],dp[i][j - 1]);
	//pprint();

	fout << dp[0][m-1];
	return 0;
}