小晴天老师系列——苹果大丰收

Problem Description

小晴天的后花园有好多好多的苹果树,某天,苹果大丰收~小晴天总共摘了M个苹果,我们假设苹果之间是不可分辨的。

为了保存苹果,小晴天买了N个一模一样的箱子,想要把苹果放进去,允许有的箱子是空的,请问小晴天有多少种不同的放法呢?

例如对于4个苹果,3个箱子,2+1+1和1+2+1和1+1+2 是同一种分法。

Input

多组数据,首先是一个正整数t(t<=100)表示数据的组数。

每组数据均包含二个整数M和N(1<=M,N<=10)。

Output

对于每组数据,输出一个整数,表示不同的放法数。

Sample Input

1
7 3

Sample Output

8

Hint

对于7个苹果,3个箱子

有7+0+0=6+1+0=5+2+0=4+3+0=5+1+1=4+2+1=3+2+2=3+3+1

这8种放法。

思路:DP解。枚举前面每个盒子可以放多少个,只要保证后面的每一个盒子中的苹果数不大于前面任意一个盒子中的苹果数即可,即让他们有序的排放在前面几个盒子中。

 /*
* this code is made by xcw0754
* Problem: 1707
* Verdict: Accepted
* Submission Date: 2015-07-15 14:06:15
* Time: 0MS
* Memory: 1676KB
*/
//#pragma comment(linker,"/STACK:102400000,102400000")
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stack>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>
#define LL long long
#define pii pair<int,int>
#define INF 0x7f7f7f7f
using namespace std;
const int N=+; vector<int> vect;
int t, nn, mm; int DFS(int m, int n, int far)
{
if( n== && far<m) return ;
if( n== && far>=m) return ;
if( m<=) return ; int ans=;
for(int i=; i<=m; i++)
{
if(far>=i)
ans+=DFS(m-i, n-, i);
}
return ans;
} int main()
{
//freopen("input.txt", "r", stdin);
cin>>t;
while(t--)
{
scanf("%d%d",&mm, &nn); //m个苹果, n个箱子
printf("%d\n",DFS(mm,nn,mm));
}
return ;
}

AC代码

最新文章

  1. Viewport---响应式 Web 设计----在路上(13)
  2. javascript练习-扑克牌
  3. Codrops 实验:使用 Vibrant.js 提取图像颜色
  4. Mac下用g++编译opencv程序报错
  5. mysql事务处理用法与实例详解
  6. iOS RSA 证书加密
  7. PDP 有多种定义,具体哪一种还需研究!!!!
  8. 【转】玩转log4j
  9. [RxJS] Introduction to RxJS Marble Testing
  10. Java或web中解决所有路径问题
  11. JS-兼容
  12. [Note] Apache Flink 的数据流编程模型
  13. YUV420格式解析
  14. Spring boot打包war包
  15. android常犯错误记录(一)
  16. curl HTTP Header
  17. POJ1185 状压dp(二进制//三进制)解法
  18. NHibernate many-to-one映射
  19. [代码]--其他信息: ORA-01400: 无法将 NULL 插入
  20. vue-router如何做历史返回提示?

热门文章

  1. Spark小课堂Week1 Hello Spark
  2. java环境搭建的问题
  3. flex打印图片
  4. 1006. Sign In and Sign Out
  5. Xubuntu 安装mentohust
  6. ISoft(开源)专用下载器
  7. 进入 App Store 打分
  8. 第一次写python
  9. js验证中英文
  10. localStorage 便签功能实现