XidianOJ 1183 Water Problem: Items divided
题目描述
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
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
#define MOD 1000000007
typedef long long LL;
LL f[][] = {},ans[][] = {};
int main(){
int n,m,i,j;
for (i=;i<=;i++){
f[i][] = ;
f[i][] = ;
f[i][i] = ;
f[][i] = ;
}
for (i=;i<=;i++){
for (j=;j<=i;j++){
if (i == j) f[i][j] = ;
else
f[i][j] = (f[i-][j-] + f[i-j][j]) % MOD;
}
}
for (i=;i<=;i++){
ans[i][] = f[i][];
for (j=;j<=i;j++){
ans[i][j] = (ans[i][j-] + f[i][j]) % MOD;
}
}
while (scanf("%d %d",&n,&m) != EOF){
if (n == && m == ) break;
// LL res = 0;
// for (i=1;i<=m;i++){
// res = (res + f[n][i]) % MOD;
// }
// printf("%lld\n",res);
printf("%lld\n",ans[n][m]);
}
return ;
}
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的更多相关文章
- Items divided
Items divided 题目链接:http://acm.xidian.edu.cn/problem.php?id=1183 参考:http://www.cnblogs.com/wanghetao/ ...
- HDU 5832 A water problem(某水题)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- hdu5832 A water problem
A water problem Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- hdu 5443 The Water Problem
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5443 The Water Problem Description In Land waterless, ...
- HDU 5867 Water problem (模拟)
Water problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5867 Description If the numbers ...
- HDU 5832 A water problem
A water problem Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- HDU 5832 A water problem (带坑水题)
A water problem 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5832 Description Two planets named H ...
- hdu 5443 The Water Problem 线段树
The Water Problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- HDU-4974 A simple water problem
http://acm.hdu.edu.cn/showproblem.php?pid=4974 话说是签到题,我也不懂什么是签到题. A simple water problem Time Limit: ...
随机推荐
- 传智播客JavaWeb day06-jstl
一.jsp标签(sun公司提供的) 二.EL表达式 三.jstl (javaserver pages standard tag library) 1.为什么要有jstl jsp标签太弱,el表达式功能 ...
- Android关联源码support-v4,v7,v13源码(转)
在Android实际开发过程中往往会遇到使用v4,v7或v13兼容包中的一些类如ViewPager,Fragment等,但却无法关联源码. 在网上搜索之后,有很多办法,这里只向大家介绍一种,我用的觉得 ...
- SQL 函数集锦
..STUFF()用另一子串替换字符串指定位置.长度的子串.STUFF (<character_expression1>, <start_ position>, <len ...
- springboot系列之-helloword入门
一. What: Spring Boot是什么?以1.4.3.RELEASE为例,官方介绍为:http://docs.spring.io/spring-boot/docs/1.4.3.RELEASE/ ...
- Array数组
array_diff_key() 例子 , , 'purple' , , 'yellow' ); var_dump(array_diff_key($array1, $array2));?> 上例 ...
- php部分---创建连接数据库类
class DBDA { public $host="localhost"; public $uid="root"; public $pwd="123 ...
- Python学习笔记——Day4
字符串操作 string典型的内置方法: count() center() startswith() find() format() lower() upper() strip() replace() ...
- Android学习五:Content Provider 使用
1ContentProvider相关知识1.1在安卓应用中,通过文件方式对外共享数据,需要进行文件操作读写数据:采用sharedpreferences共享数据,需要使用sharedpreference ...
- SSH 创建证书认证
*******chmod 600 195-tempuser.txt******* useradd tempusersu tempusercdmkdir .sshchmod 700 .sshcd .ss ...
- Android定时器Timer.schedule
Timer是一种定时器工具,用来在一个后台线程计划执行指定任务.它可以计划执行一个任务一次或反复多次.TimerTask一个抽象类,它的子类代表一个可以被Timer计划的任务. schedule的意思 ...