您的位置:首页 > 其它

hut 1574 组合问题 解题报告

2011-08-07 19:36 316 查看
链接:http://openoj.awaysoft.com/JudgeOnline/problem.php?id=1574

Description

有n 种颜色的球,每种颜色的球的个数有任意多个,从中取m个,问有多少种取法

Input

每行2个正整数 n,m(<=31) ,n=0,m=0结束.


Output

输出有多少种取法


Sample Input

2 2
3 3
0 0

Sample Output

3
10

本题是一个纯组合问题,题意也比较简单即:从无限多重集中取若干元素的组合数
N = C( n+m-1 , m )
再通过组合数性质C( n, m ) = C( n-1, m ) + C( n-1, m-1 ),直接打表无压力水过。

#include <stdio.h>
#include <stdlib.h>
long long a[40][40];
void fun(  )
{
a[1][0]=a[1][1]=1;
for( int i=2; i<40; ++i )
{
a[i][0]=1;
a[i][1]=i;
for( int j=2; j<40; ++j )
{
a[i][j]=a[i-1][j]+a[i-1][j-1];
}
}
}
int main()
{
fun( );
int n, m;
while( scanf( "%d%d", &n, &m ) != EOF , n+m)
{
printf( "%lld\n", a[n+m-1][m] );
}
return 0;
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: