Description:

Erin买了不少鸡蛋,她发现一天吃不完这么多,于是决定把n个同样的鸡蛋放在m个同样的篮子里,允许有的篮子空着不放,请问共有多少种不同的放法呢?

注意:2,1,1和1,2,1 是同一种分法。

Input

第一行是测试数据的数目t(0 <= t <= 20)。以下每行均包含二个整数m和n,以空格分开。1<=m,n<=10。

Output

对输入的每组数据m和n,用一行输出相应的结果。

例如:

Input:

4

3 8

4 7

2 4

4 2

Output:

10

11

3

2

(注意结尾有换行)


Hint:

尝试利用递归去分析解题,即不同情况下应该怎么返回。

可以尝试用树状图(然而我觉得用处不大)。

注意篮子可以空着不放,请先想明白示例中最后两个例子再做题。


我的代码:

#include<stdio.h>
int egg(int m, int n);
int main() {
int t, m, n, i, result = ;
scanf("%d", &t);
for (i = ; i < t; i++) {
scanf("%d%d", &m, &n);
result = egg(m, n);
printf("%d\n", result);
}
return ;
}
int egg(int m, int n) {
if (m == || n == ) {
return ;
}
if (n <= m) {
return + egg(n-, n);
} else {
return egg(m-, n) + egg(m, n-m);
}
}

标答:

#include<stdio.h>
int egg(int m, int n); int main() {
int t;
// m for baskets, n for eggs
int m, n;
int result = ;
scanf("%d", &t);
while (t--) {
scanf("%d %d", &m, &n);
result = egg(m , n);
printf("%d\n", result);
}
return ;
} int egg(int m, int n) {
if (m == || n == )
return ;
if (n < )
return ;
return egg(m-, n) + egg(m, n-m);
}

eggs的更多相关文章

  1. [CareerCup] 6.5 Drop Eggs 扔鸡蛋问题

    6.5 There is a building of 100 floors. If an egg drops from the Nth floor or above, it will break. I ...

  2. SZU:B85 Alec's Eggs

    Description Eggs Alec has a lot of eggs. One day, he want to sort them in a ascending sequence by we ...

  3. cooking eggs

    1: what is egg? what's the shape of it in details? 2: can egg run like this http://item.taobao.com/i ...

  4. Golden Eggs HDU - 3820(最小割)

    Golden Eggs Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. HDU 3820 Golden Eggs (SAP | Dinic)

    Golden Eggs Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  6. 100 floors 2 eggs

    https://github.com/Premiumlab/Python-for-Algorithms--Data-Structures--and-Interviews/blob/master/Moc ...

  7. 254. Drop Eggs【LintCode java】

    Description There is a building of n floors. If an egg drops from the k th floor or above, it will b ...

  8. HDU 3820 Golden Eggs( 最小割 奇特建图)经典

    Golden Eggs Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  9. 贪心 Codeforces Round #173 (Div. 2) B. Painting Eggs

    题目传送门 /* 题意:给出一种方案使得abs (A - G) <= 500,否则输出-1 贪心:每次选取使他们相差最小的,然而并没有-1:) */ #include <cstdio> ...

随机推荐

  1. glibc CVE-2015-7547漏洞的分析和修复方法【转】

    本文转载自:http://blog.csdn.net/tengxy_cloud/article/details/50764370 漏洞概述 glibc中处理DNS查询的代码中存在栈溢出漏洞,远端攻击者 ...

  2. lucene 5的测试程序——API变动太大

    package hello; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import ...

  3. [原创]java获取word里面的文本

    需求场景 开发的web办公系统如果需要处理大量的Word文档(比如有成千上万个文档),用户一定提出查找包含某些关键字的文档的需求,这就要求能够读取 word 中的文字内容,而忽略其中的文字样式.表格. ...

  4. 阮一峰 KMP BM算法

    存一个链接,讲得好啊! 点击这里打开     字符串KMP 点击这里打开     字符串匹配的Boyer-Moore算法

  5. [USACO2006 DEC] Wormholes

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1715 [算法] 用SPFA判定负环是否存在即可 时间复杂度 : O(N ^ 2) [ ...

  6. 【JSOI 2009】 Count

    [题目链接] 点击打开链接 [算法] 二维树状数组 [代码] #include<bits/stdc++.h> using namespace std; #define MAXN 300 # ...

  7. Filter的基本配置

    1.<dispatcher></dispatcher>节点:指定过滤器所拦截的servlet容器调用资源的方式,有REQUEST,INCLUDE,FORWARD,ERROR,默 ...

  8. .NETFramework:Stopwatch

    ylbtech-.NETFramework:Stopwatch 1.返回顶部 1. #region 程序集 System, Version=4.0.0.0, Culture=neutral, Publ ...

  9. MFC程序中的 _T("") 什么意思?

    _T("")就是把引号内的字符串转换为宽字节的Unicode编码 宽字节就是unicode.

  10. 使用mysqlfrm恢复frm表结构,获得建表语句

    1.mysqlfrm 是一个恢复性质的工具,用来读取.frm文件并从该文件中找到表定义数据生成CREATE语句. 下载链接:https://downloads.mysql.com/archives/u ...