eggs
Description:
Erin买了不少鸡蛋,她发现一天吃不完这么多,于是决定把n个同样的鸡蛋放在m个同样的篮子里,允许有的篮子空着不放,请问共有多少种不同的放法呢?
注意:2,1,1和1,2,1 是同一种分法。
第一行是测试数据的数目t(0 <= t <= 20)。以下每行均包含二个整数m和n,以空格分开。1<=m,n<=10。
对输入的每组数据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的更多相关文章
- [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 ...
- 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 ...
- 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 ...
- Golden Eggs HDU - 3820(最小割)
Golden Eggs Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 3820 Golden Eggs (SAP | Dinic)
Golden Eggs Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- 100 floors 2 eggs
https://github.com/Premiumlab/Python-for-Algorithms--Data-Structures--and-Interviews/blob/master/Moc ...
- 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 ...
- HDU 3820 Golden Eggs( 最小割 奇特建图)经典
Golden Eggs Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- 贪心 Codeforces Round #173 (Div. 2) B. Painting Eggs
题目传送门 /* 题意:给出一种方案使得abs (A - G) <= 500,否则输出-1 贪心:每次选取使他们相差最小的,然而并没有-1:) */ #include <cstdio> ...
随机推荐
- 为了cider,尝试emacs的坑
https://github.com/clojure-emacs/cider http://clojure-doc.org/articles/tutorials/emacs.html emacs通过b ...
- POJ2752 Seek the Name, Seek the Fame —— KMP next数组
题目链接:https://vjudge.net/problem/POJ-2752 Seek the Name, Seek the Fame Time Limit: 2000MS Memory Li ...
- POJ1300 Door Man —— 欧拉回路(无向图)
题目链接:http://poj.org/problem?id=1300 Door Man Time Limit: 1000MS Memory Limit: 10000K Total Submiss ...
- oracle:rman恢复----通过时间set until time
试验计划:先做一个0级备份,再创建一个表,插入几条数据,最后删除表,然后通过rman把该表的数据恢复. 试验环境:在归档模式,oracle10.2.0.1 开始试验: 1.rman level 0备份 ...
- hdu 4300 Clairewd’s message(kmp/扩展kmp)
题意:真难懂.. 给出26个英文字母的加密表,明文中的'a'会转为加密表中的第一个字母,'b'转为第二个,...依次类推. 然后第二行是一个字符串(str1),形式是密文+明文,其中密文一定完整,而明 ...
- VS2010中编写x64汇编的具体方法
编写涉及系统特性的一些底层程序,特别是ShellCode,不可避免地要采用直接编写汇编代码的方式. 在目标平台为x86模式时,可以直接使用内联汇编,这个很多人都比较熟悉了,也非常地方便. 但是当目标平 ...
- BackTrack5(BT5)各版本下载
BT5R3(最新版本)http://www.nigesb.com/backtrack-5-r3-released.html BT5R2KDE版32位: http://ftp.halifax.rwth ...
- BZOJ3990 排序
题目:www.lydsy.com/JudgeOnline/problem.php?id=3990 这题很不错. 刚开始时无从下手,想了好多$O((2^n)log(2^n))$ 的idea,但是都不行. ...
- windows 远程连接 密码正确但是无法登陆,提示证书不正确
问题: windows8.1 远程连接 windows8 进入输入用户名密码环节,用户名,密码都正确,但是无法登陆 连接时,下方写着 域名 MicrosoftAccount 解决: 在输入密码后,点击 ...
- noip 2018 Day2 T1 旅行
暴力删边,暴力枚举 #include <bits/stdc++.h> using namespace std; #define MAXM 5010 inline int read() { ...