Description of the problem 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
Exercises
#include <stdio.h>#include<algorithm>#include<string.h>using namespacestd;intMain () {intN, M;//m for shoe change, n for borrow shoes intf[ -][ -];//F[x][y] Indicates the number of shoes to be borrowed and shoes to change x, yMemset (F,0,sizeof(f)); scanf ("%d%d", &n, &m); for(inti =1; I <= N; i++) f[i][0] =1; for(inti =1; I <= m; i++) f[0][i] =1; for(inti =1; I <= N; i++) { for(intj =1; J <= M; J + +) { if(i = =j) F[i][j]= f[i][j-1]; Else if(I >j) F[i][j]= f[i-1][J] + f[i][j-1]; }} printf ("%d\n", F[n][m]); return 0;}
View Code
Algorithm to train the annoyance of an unnamed lake (recursive)