Blue Bridge Cup practice system-algorithm training Peiling's troubles

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.