Problem description
Every winter, Peking University is a good place for skating on the lake. The Peking University sports team has prepared many skates, but there are 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 with the same needs (such as renting shoes or all shoes) Exchange position is the same row method)
Input format
Two integers representing M and n
Output format
An integer that represents the number of schemes for the troop's platoon.
Sample input
3 2
Sample output
5
Data size and conventions
M,N∈[0,18]
Analysis: Enumerate all cases and analyze them individually
Code:
#include <iostream>using namespacestd;intm, N;intAns =0;inta[ +];intb[ +];voidSolveintcur) { if(cur = = m+N) {intFlag =0; for(inti =0; i < m+n; i++) { if(B[i]) flag++; Elseflag--; if(Flag <0) Break; } if(Flag >=0) ans++; } Else for(inti =0; i < m+n; i++) { if(!i | | a[i]! = a[i-1]) { intC1 =0, C2 =0; for(intj =0; J < cur; J + +)if(A[i] = = B[j]) c1++; for(intj =0; J < M+n; J + +)if(A[i] = = A[j]) c2++; if(C1 <C2) {B[cur]=A[i]; Solve (cur+1); } } }}intMain () {CIN>> m >>N; for(inti =0; I < m; i++) A[i] =1; for(inti = m; I < n; i++) A[i] =0; Solve (0); cout<< ans <<Endl;}
Blue Bridge Cup practice system-algorithm training Peiling's troubles