"Recursion" put the apple

Source: Internet
Author: User

"Recursion" put the apple Title Description Chuji just took the oil to the kitchen, and mother shouted: "Go and wash the apples and put them on the plate." ”

Chuji to put m the same apples on n the same plate, allowing some plates to be empty, asking how many different ways are there? (denoted by K) 5, 1, 1 and 1, 5, 1 are the same kind of sub-method. Enter the 1th behavior an integer that represents the number of test data (number of test data T (0≤t≤20), 2nd behavior m and N (M and N, separated by spaces. 1≤M,N≤10). How many different sub-methods are available for output output. Sample input
17 3
Sample output
8
Analysis: A kind of ball box problem;
If you are using a K-plate, put an apple on the K-plate, or convert it to a K-1 plate;
#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<algorithm>#include<climits>#include<cstring>#include<string>#include<Set>#include<map>#include<queue>#include<stack>#include<vector>#include<list>#defineRep (I,m,n) for (i=m;i<=n;i++)#defineRSP (It,s) for (Set<int>::iterator It=s.begin (); It!=s.end (); it++)#defineMoD 1000000007#defineINF 0x3f3f3f3f#defineVI vector<int>#definePB Push_back#defineMP Make_pair#defineFi first#defineSe Second#definell Long Long#definePi ACOs (-1.0)Const intmaxn=1e6+Ten;Const intdis[][2]={0,1,-1,0,0,-1,1,0};using namespacestd;ll gcd (ll p,ll q) {returnq==0? P:GCD (q,p%q);} ll Qpow (ll p,ll q) {ll F=1; while(q) {if(q&1) f=f*p%mod;p=p*p%mod;q>>=1;}returnF;} ll Dfs (intAintp) {    if(a<=1|| p<=1)return 1; Else if(a<p)returnDFS (A,A); Else returnDFS (A-P,P) +dfs (a,p-1);}intMain () {inti,j,m,n,k,t; scanf ("%d",&t);  while(t--) {scanf ("%d%d",&m,&N); printf ("%lld\n", DFS (m,n)); }    //System ("pause");    return 0;}

"Recursion" put the apple

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.