800602分苹果 |
难度级别:B; 运行时间限制:1000ms; 运行空间限制:51200KB; 代码长度限制:2000000B |
试题描述
|
把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法。
|
输入
|
第一行是测试数据的数目t,以下每行均包含二个整数M和N,以空格分开。
|
输出
|
对输入的每组数据M和N,用一行输出相应的K。
|
输入示例
|
1
7 3 |
输出示例
|
8
|
其他说明
|
数据范围:0<=t<=20,1<=M,N<=10。
|
题解:经典以0分dp。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstring>
#define PAU putchar(' ')
#define ENT putchar('\n')
using namespace std;
int fun(int m,int n){
if(!m||n==)return ;
if(n>m)return fun(m,m);
else return fun(m,n-)+fun(m-n,n);
}
inline int read(){
int x=,sig=;char ch=getchar();
for(;!isdigit(ch);ch=getchar())if(ch=='-')sig=;
for(;isdigit(ch);ch=getchar())x=*x+ch-'';
return sig?x:-x;
}
inline void write(int x){
if(x==){putchar('');return;}if(x<)putchar('-'),x=-x;
int len=,buf[];while(x)buf[len++]=x%,x/=;
for(int i=len-;i>=;i--)putchar(buf[i]+'');return;
}
void init(){
int T=read();int m,n;
while(T--){
m=read();n=read();
write(fun(m,n));ENT;
}
return;
}
void work(){
return;
}
void print(){
return;
}
int main(){init();work();print();return ;}