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. js中的关系操作符

    1.关于“小于(<)” a.关于数值的判断就是跟正常的比较一样: b.var result = “23” <"3" ;  //true 这两个是字符串,会比较他们的编码 ...

  2. CodeForces - 55D Beautiful numbers —— 数位DP

    题目链接:https://vjudge.net/problem/CodeForces-55D D. Beautiful numbers time limit per test 4 seconds me ...

  3. 修改DEDE系统数据库表前缀

    1,修改之前我们先备份下数据(哥们儿之前没有备份,我艹,害苦了),备份的操作过程是:网站后台------系统------数据库备份/还原-------然后按提交.默认保存的数据在data/backup ...

  4. MySQL性能优化-I/O相关配置参数

    本文介绍InnoDB和MyISAM两种存储引擎的I/O相关参数配置. 1.InnoDB  I/O相关配置 Innodb是一种事务型的存储引擎,为了减少提交事务时产生的io开销,innodb采用了写日志 ...

  5. codeforces 443 B. Kolya and Tandem Repeat 解题报告

    题目链接:http://codeforces.com/contest/443/problem/B 题目意思:给出一个只有小写字母的字符串s(假设长度为len),在其后可以添加 k 个长度的字符,形成一 ...

  6. oracle:程序后台提示Io异常: The Network Adapter could not establish the connection)

    今天要用tomcat部署一个系统,windows环境下,oracle和程序在一台机器上. 在配置jndi时,直接写成 jdbc:oracle:thin:@127.0.0.1:1521:orcl.启动程 ...

  7. Oracle:impdb导入

    最近有现场给我一份用expdp导出dmp文件,我用imp导入时,报错.因为导出dmp的数据库是11g,导入的数据库也是11g, 但客户端安装的是10g,不能用imp导入:所以只能试着用impdp导入: ...

  8. LA-2678 (尺取法)

    题意: 在一个长度为n的序列中,找到最短的长度序列,使其和大于等于s; 思路: two pointer ,水题; Ac代码: #include <bits/stdc++.h> /* #in ...

  9. 区间DP 青蛙的烦恼

    池塘中有n片荷叶恰好围成了一个凸多边形,有一只小青蛙恰好站在1号荷叶上,小青蛙想通过最短的路程遍历所有的荷叶(经过一个荷叶一次且仅一次),小青蛙可以从一片荷叶上跳到另外任意一片荷叶上. 输入数据(fr ...

  10. CreateRemoteThread注入DLL

    DLL注入的常用方式之一远程线程注入,实现代码如下 // CreateRemoteThread.cpp : Defines the entry point for the application.// ...