Algorithm training The trouble time limit of the unnamed lake: 1.0s memory Limit: 256.0MB problem description Every winter, the North Lake is a good place to skate. Peking University sports team prepared a lot of skates, but too many people, every afternoon after the day, often a pair of skates are not left.
Every morning, rental shoes window will be lined up long, fake with shoes of M, there is need to rent shoes n. The question now is how many of these people have a way to avoid embarrassing situations where the sports Group has no skates to rent. (Two people who have the same needs (such as rent shoes or shoes) Exchange position is the same row method) the input format is two integers, representing the M and n output formats an integer representing the number of schemes for the queue. Sample Input 3 2 sample output 5 data size and convention m,n∈[0,18]
Problem analysis
Idea: F (m-1,n) +f (m,n-1), also shoes in the first + rent shoes in the first one
AC Code:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
# Include <climits>
#include <cmath>
#include <cctype>
typedef long Long ll;
using namespace std;
int f (int m,int N)
{
if (M < n)
return 0;
if (n = = 0)
return 1;
return f (m-1,n) + f (m,n-1);
}
int main ()
{
int m,n;
while (scanf ("%d%d", &m,&n)! = EOF)
{
int sum = f (m,n);
printf ("%d\n", sum);
}
return 0;
}