题目描述

Youyouyouyou is very interested in math, one day, an idea came into his mind that how many ways he can patition n same things into no more than m groups? he think it too hard for him, so youyouyouyou ask wise cyt for help, but wise cyt don’t want to talk with youyouyouyou because it is too easy for him, now can you help youyouyouyou solve this problem?

输入

multi test cases, two integers n and m(1<=m<=n<=1000) , end with n = m = 0.

输出

output

  1. #include <cstdio>
  2. #include <algorithm>
  3. #include <iostream>
  4. using namespace std;
  5. #define MOD 1000000007
  6. typedef long long LL;
  7. LL f[][] = {},ans[][] = {};
  8. int main(){
  9. int n,m,i,j;
  10. for (i=;i<=;i++){
  11. f[i][] = ;
  12. f[i][] = ;
  13. f[i][i] = ;
  14. f[][i] = ;
  15. }
  16. for (i=;i<=;i++){
  17. for (j=;j<=i;j++){
  18. if (i == j) f[i][j] = ;
  19. else
  20. f[i][j] = (f[i-][j-] + f[i-j][j]) % MOD;
  21. }
  22. }
  23. for (i=;i<=;i++){
  24. ans[i][] = f[i][];
  25. for (j=;j<=i;j++){
  26. ans[i][j] = (ans[i][j-] + f[i][j]) % MOD;
  27. }
  28. }
  29. while (scanf("%d %d",&n,&m) != EOF){
  30. if (n == && m == ) break;
  31. // LL res = 0;
  32. // for (i=1;i<=m;i++){
  33. // res = (res + f[n][i]) % MOD;
  34. // }
  35. // printf("%lld\n",res);
  36. printf("%lld\n",ans[n][m]);
  37. }
  38. return ;
  39. }

an answer modulo 1e9 + 7 per line

--正文

n个相同的球放入m个相同的盒子,允许有空盒

F(n,m) = F(n-1,m-1) + F(n-m,m)

注意边界的处理

XidianOJ 1183 Water Problem: Items divided的更多相关文章

  1. Items divided

    Items divided 题目链接:http://acm.xidian.edu.cn/problem.php?id=1183 参考:http://www.cnblogs.com/wanghetao/ ...

  2. HDU 5832 A water problem(某水题)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  3. hdu5832 A water problem

    A water problem Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  4. hdu 5443 The Water Problem

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5443 The Water Problem Description In Land waterless, ...

  5. HDU 5867 Water problem (模拟)

    Water problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5867 Description If the numbers ...

  6. HDU 5832 A water problem

    A water problem Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  7. HDU 5832 A water problem (带坑水题)

    A water problem 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5832 Description Two planets named H ...

  8. hdu 5443 The Water Problem 线段树

    The Water Problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  9. HDU-4974 A simple water problem

    http://acm.hdu.edu.cn/showproblem.php?pid=4974 话说是签到题,我也不懂什么是签到题. A simple water problem Time Limit: ...

随机推荐

  1. iOS-服务器文件断点下载

    文件下载基本步骤:1.获取下载链接,创建响应发送请求.(使用异步请求,避免因文件过大下载时间长而阻塞主线程).2.当接到响应时在下载目录中创建文件.创建文件使用NSFileHandle进行文件内部处理 ...

  2. 计算DNA中每种核苷酸的数目

    问题描述:计算DNA中每种核苷酸的数目 输入文件内容: 代码: 输出结果:

  3. ✡ leetcode 167. Two Sum II - Input array is sorted 求两数相加等于一个数的位置 --------- java

    Given an array of integers that is already sorted in ascending order, find two numbers such that the ...

  4. android之OptionMenu

    一.现在我给大家介绍两个不同版本的模拟器(2.3.3和4.0.3) 1.布局文件 (1)打开“res/layout/activity_main.xml”文件. 先看mian布局文件 <Relat ...

  5. codeForce-589D Boulevard(判断线段是否相交)

    题目大意:n个人.一个区间.每个人都会在某个时间段内按相同的速度(所有人的速度都一样,都是1或-1)在他的区间内从一个端点走到另一个端点(只走一次).问每个人会与几个人碰面. 题目分析:将时间看成一个 ...

  6. HTML5 history新特性pushState、replaceState,popstate

    http://blog.csdn.net/tianyitianyi1/article/details/7426606 https://developer.mozilla.org/zh-CN/docs/ ...

  7. 030. asp.net中DataList数据绑定跳转(两种方式)的完整示例

    前台代码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.as ...

  8. unity, 由scriptableObject创建.asset

    由继承自scriptableObject的类X创建.asset文件. 假设类X的定义为: [System.Serializable] public class X : ScriptableObject ...

  9. Centos 安装vsftpd 服务器

    一:检查有没有安装vsftpd 二:安装vsftpd 三:安装之后重启 四:修改vsftpd配置文件 配置文件路径在/etc/vsftpd目录下 默认是注释掉的,把#号去掉 然后重启vsftpd 五: ...

  10. SPRING + THYMELEAF 配置

    1.使用的是Spring EL而不是Ognl.2.访问上下文的Bean用${@myBean.doSomething()}3.th:field,th:errors,th:errorclass用于form ...