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[1001][1001] = {0},ans[1001][1001] = {0};
int main(){
    int n,m,i,j;
    for (i=1;i<=1000;i++){
        f[i][0] = 0;
        f[i][1] = 1;
        f[i][i] = 1;
        f[0][i] = 0;
    }
    for (i=1;i<=1000;i++){
        for (j=1;j<=i;j++){
            if (i == j) f[i][j] = 1;
            else
                f[i][j] = (f[i-1][j-1] + f[i-j][j]) % MOD;
        }
    }
    for (i=1;i<=1000;i++){
        ans[i][1] = f[i][1];
        for (j=2;j<=i;j++){
            ans[i][j] = (ans[i][j-1] + f[i][j]) % MOD;
        }
    }
    while (scanf("%d %d",&n,&m) != EOF){
        if (n == 0 && m == 0) 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 0;
} 

an answer modulo 1e9 + 7 per line

--正文

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

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

注意边界的处理

时间: 2024-10-17 06:39:06

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

Items divided

Items divided 题目链接:http://acm.xidian.edu.cn/problem.php?id=1183 参考:http://www.cnblogs.com/wanghetao/archive/2013/11/25/3442192.html 划分数(dp) 以前划分数没仔细看,拿到这题的时候随便弄了个dp,调了半个多小时,结束后才发现转移方程写错了= = dp[i][j]表示将i划分成j个正整数的划分数,之后有以下三种情况: 1.i<j    此时i不可能划分成j个正整数,

Water Problem

water problem 发布时间: 2015年10月10日 15:34   时间限制: 1000ms   内存限制: 256M 描述 题意很简单 给你N个数, Q个查询 每次查询给你一个区间[L, R] 你要找出 [L, R] 这个区间里面取模M后的最大值. 输入 第一行一个T,表示测试数据组数.第二行两个整数N, M (1<=N<=10^5, 1<=M<=10^9).第三行给你N个整数 整数范围在1到10^9之间.第四行给你一个整数Q. ( 1<=Q<=10^5)

hdu 4974 A simple water problem(数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4974 Problem Description Dragon is watching competitions on TV. Every competition is held between two competitors, and surely Dragon's favorite. After each competition he will give a score of either 0 or

dutacm.club Water Problem(矩阵快速幂)

Water Problem Time Limit:3000/1000 MS (Java/Others)   Memory Limit:163840/131072 KB (Java/Others)Total Submissions:1228   Accepted:121 [Submit][Status][Discuss] Description 函数 f:Z+→Z .已知 f(1),f(2) 的值,且对于任意 x>1,有 f(x+1)=f(x)+f(x?1)+sin(πx2) . 求 f(n) 的

HDU 4974 A simple water problem(贪心)

HDU 4974 A simple water problem 题目链接 签到题,很容易贪心得到答案是(sum + 1) / 2和ai最大值的最大值 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N = 100005; typedef long long ll; int t, n; ll a, Max, sum; int main(

HDU - 4974 A simple water problem

Problem Description Dragon is watching competitions on TV. Every competition is held between two competitors, and surely Dragon's favorite. After each competition he will give a score of either 0 or 1 for each competitor and add it to the total score

HDOJ 4974 A simple water problem

A simple water problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 173    Accepted Submission(s): 112 Problem Description Dragon is watching competitions on TV. Every competition is held be

2014多校第十场1004 || HDU 4974 A simple water problem

题目链接 题意 : n支队伍,每场两个队伍表演,有可能两个队伍都得一分,也可能其中一个队伍一分,也可能都是0分,每个队伍将参加的场次得到的分数加起来,给你每个队伍最终得分,让你计算至少表演了几场. 思路 : ans = max(maxx,(sum+1)/2) :其实想想就可以,如果所有得分中最大值没有和的一半大,那就是队伍中一半一半对打,否则的话最大的那个就都包了. 1 #include <cstdio> 2 #include <cstring> 3 #include <st

ACDream 1734 Can you make a water problem?(贪心)

Can you make a water problem? Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Submit Statistic Next Problem Problem Description Losanto want to make a water problem. But he have no idea….Then he thought a problem: A b