Beautiful violence and acdream Violence Session in acdream brute force session
F-xiaosunday instructor series-Apple's bumper harvest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 128000/64000 KB (Java/Others) Problem Description
There are a lot of apple trees in the back garden on a sunny day ~ On a sunny day, we picked a total of M apples. We suppose there is no difference between them.
In order to save the apple, I bought N identical boxes on a sunny day. I want to put the apple in. Some boxes are allowed to be empty. How many different methods can I use in Xiaoqing?
For example, for four apples and three boxes, 2 + 1 + 1 and 1 + 2 + 1 and 1 + 1 + 2 are the same method.
Input
For multiple groups of data, a positive integer t (t <= 100) indicates the number of groups of data.
Each group of data contains two integers, M and N (1 <= M, N <= 10 ).
Output outputs an integer for each group of data, indicating different placement methods. Sample Input
17 3
Sample Output
8
Hint
For 7 apples, 3 boxes
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 eight release methods.
Solution! Pure violence ~
Reference code:
#include<stdio.h>int main(void){ int i,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==10 && i+i1+i2+i3+i4+i5+i6+i7+i8+i9==M) z++; } } } } } } } } } } printf("%d\n",z); } return 0;}