Sicily 1715. A piece of cake
来源:互联网 发布:showgirl是什么软件 编辑:程序博客网 时间:2024/06/16 03:09
1715. A piece of cake
Constraints
Time Limit: 1 secs, Memory Limit: 32 MB
Description
This problem is very simple, i.e. just a piece of cake for you, excellent programmers. You just need to calculate and output how many ways to put n different balls into m different boxes so that each box has at least k balls.
Input
Input contains several test cases. Each of the test cases contains three integers in one line, n, m, k (1 <= n, m <= 15, 0 <= k <= 15). Input is terminated by three 0s, which should not be processed.
Output
For each case, just print the result in one line. Heading zeros are forbidden. For example, 12 is legal output but 012 is not, 0 is legal but 00 is not, and so on.
Sample Input
3 3 12 4 13 2 00 0 0
Sample Output
608
// Problem#: 1715// Submission#: 3585085// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/// All Copyright reserved by Informatic Lab of Sun Yat-sen University#include <stdio.h>int n, m, k;long long mat[60][60];long long gcd(long long a, long long b) { long long r; while (b) { r = a % b; a = b; b = r; } return a;}long long c(int a, int b) { long long x = 1, y = 1; long long r; int i; for (i = 0; i < b; i++) { x *= (a - i); y *= (b - i); r = gcd(x, y); x /= r; y /= r; } return x / y;}void process() { int i, j, u; for (i = 0; i <= n; i++) for (j = 0; j <= m; j++) mat[i][j] = 0; for (i = 0; i <= n; i++) mat[i][0] = 0; mat[0][0] = 1; for (i = 1; i <= m; i++) for (j = k * i; j <= n; j++) { mat[j][i] = 0; for (u = k; u <= j - (i - 1) * k; u++) { long long temp = c(j, u); mat[j][i] = mat[j][i] + temp * mat[j - u][i - 1]; } } printf("%lld\n", mat[n][m]);}int main() { while (scanf("%d%d%d", &n, &m, &k) == 3) { if (n == 0) break; process(); } return 0;}
0 0
- Sicily 1715. A piece of cake
- SpokenEnglish--It's a piece of cake
- Piece of Cake
- a piece of cake,IOS simulator横竖屏显示问题
- Tip of today-A Piece of Cake 蛋糕我爱吃
- A Piece Of My Heart
- Win32/FakeSecSen - A Nasty Piece of Work
- do you want a piece of me
- One piece of collection and a little progress everyday.
- A little piece of me 生命的过客
- The OpenOffice Writer is A PIECE OF SHIT!!!!!
- rowid format and the format of a row piece
- How to disable compiler optimization for a piece of code
- [ZOJ1460]The Partition of a Cake
- zoj 1460 The Partition of a Cake
- piece of code(2)
- piece of code(3)
- piece of code(4)
- ssh框架配置数据源 数据库连接没有正常释放
- 感恩2014
- C语言进阶3
- webservice加载到tomcat的事项以及mysql和服务器的连接
- Android studio修改debug.keystore
- Sicily 1715. A piece of cake
- 【福建省赛】Bilibili(线段树 单点更新,成段查询)
- 线程属性讲解及线程属性操作函数
- Sicily 1032. Depot
- HDU 1272 小希的迷宫(并查集)
- Sicily 1740. Investment
- Sicily 1739. Helpful papers
- log4J配置,和使用
- Reverse Bits