题目:
Placing apples
View Submit Statistics Hint Clarify
总Time Limit: 1000ms Memory Limit: 65536kB
Description
We are going to place M same apples into N same plates.
There could be some empty plates.
How many methods do we have?
When we have 7 applesand 3 plates, the methods, (1, 5, 1) and (5, 1, 1) are the same.
Input
The first line is the number of test cases, t. 0<=t<=20
The next t lines are test cases containing two numbers, M and N. 1<=M, N<=10.
Output
Output the numbers of method in each test case in one line.
Sample Input
1
7 3
Sample Output
8
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int ans;
int dfs(int m, int n){
if(m== || n==) return ;
if(m<n) return dfs(m, m);
else if(m==n) return +dfs(m, m-);
else return dfs(m, n-) + dfs(m-n, n);
}
int main(){
int t, m, n;
cin>>t;
while(t--){
cin>>m>>n;
cout<<dfs(m, n)<<endl;
}
return ;
}
好的题解以及关于整数拆分的博客:
http://blog.csdn.net/pi9nc/article/details/8142091
http://blog.chinaunix.net/uid-26548237-id-3503956.html
http://www.cnblogs.com/xiaoxian1369/archive/2011/09/12/2174212.html
https://site.douban.com/191996/widget/notes/11374359/note/262068151/
http://www.cppblog.com/superKiki/archive/2010/05/27/116506.html