OJ clicks calculation questions and oj clicks calculation questions
Description
For a simple calculation, You need to calculate f (m, n), which is defined as follows: When m = 1, f (m, n) = n; when n = 1, f (m, n) = m; when m> 1, n> 1, f (m, n) = f (S-1, n) + f (m, n-1)
Input
The first row contains an integer T (1 <=t <= 100), indicating the number of data groups below. The following T rows, where each group of data has two integers m, n (1 <= m, n <= 2000), separated by spaces.
Output
For each group of input data, you need to calculate f (m, n) and output it. Each result occupies one row.
Sample Input
2
1 1
2 3
Sample output
1
7
The Code is as follows:
#include <iostream>using namespace std;int f(int, int);int main(){int m, n, T, i , str[100];cin >> T;if (T >= 1 && T <= 100){ for (i=0;i<T;++i) {cin >> m >> n;str[i] = f(m, n); }for (i = 0; i < T; ++i)cout << str[i] << endl;}return 0;}int f(int m, int n){if (m == 1)return n;else if (n == 1)return m;else if (m == 1 && n == 1)return 1;else if (m > 1 && n > 1)return (f(m - 1, n) + f(m, n - 1));}
Running result: