F-Small sunny teacher series--Apple Bumper HarvestTime Limit:2000/1000ms (java/others) Memory Limit: 128000/64000kb (java/others) Problem Description
Small sunny back garden there are many apple trees, one day, Apple bumper harvest ~ Small Sunny A total of picking m apples, we assume that the apple is indistinguishable.
In order to save apples, a small sunny day to buy n an identical box, want to put the apple in, allow some boxes is empty, how many different ways to put a small sunny day?
For example, for 4 apples, 3 chests, 2+1+1 and 1+2+1, and 1+1+2 are the same kind of sub-method.
Input
Multiple sets of data, first, a positive integer t (t<=100) that represents the number of groups of data.
Each group of data contains two integers M and N (1<=m,n<=10).
Output for each set of data, outputs an integer that represents a different number of methods of discharge. Sample Input
17 3
Sample Output
8
Hint
For 7 apples, 3 boxes
Have 7+0+0=6+1+0=5+2+0=4+3+0=5+1+1=4+2+1=3+2+2=3+3+1
These 8 kinds of methods.
Solution: Ten for brute force crack, in order to avoid duplication, so set the back of the box can not be less than the front of the box to put apples! Pure violence ~
Reference code:
#include <stdio.h>intMainvoid){ inti,i1,i2,i3,i4,i5,i6,i7,i8,i9,t,m,n,z; scanf ("%d",&T); while(t--) {scanf ("%d%d",&m,&N); for(z=1, i=0; i<m;i++){ if(n==1&& i==m) z++; for(I1=i; N>1, i1<m;i1++){ if(n==2&& i+i1==m) z++; for(I2=I1; N>2, i2<m;i2++){ if(n==3&& i+i1+i2==m) z++; for(I3=I2; N>3, i3<m;i3++){ if(n==4&& i+i1+i2+i3==m) z++; for(I4=I3; N>4, i4<m;i4++){ if(n==5&& i+i1+i2+i3+i4==m) z++; for(I5=I4; N>5, i5<m;i5++){ if(n==6&& i+i1+i2+i3+i4+i5==m) z++; for(I6=I5; N>6, i6<m;i6++){ if(n==7&& i+i1+i2+i3+i4+i5+i6==m) z++; for(I7=I6; N>7, i7<m;i7++){ if(n==8&& i+i1+i2+i3+i4+i5+i6+i7==m) z++; for(I8=I7; N>8, i8<m;i8++){ if(n==9&& i+i1+i2+i3+i4+i5+i6+i7+i8==m) z++; for(I9=I8; N>9, i9<m;i9++){ if(n==Ten&& i+i1+i2+i3+i4+i5+i6+i7+i8+i9==m) z++; } } } } }}}}}} printf ("%d\n", z); } return 0;}
The graceful violence in the acdream violent session