排列组合

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4891    Accepted Submission(s): 2122

Problem Description
有n种物品,并且知道每种物品的数量。要求从中选出m件物品的排列数。例如有两种物品A,B,并且数量都是1,从中选2件物品,则排列有"AB","BA"两种。
 
Input
每组输入数据有两行,第一行是二个数n,m(1<=m,n<=10),表示物品数,第二行有n个数,分别表示这n件物品的数量。
 
Output
对应每组数据输出排列数。(任何运算不会超出2^31的范围)
 
Sample Input
2 2
1 1
 
Sample Output
2
 
Author
xhd
 
Recommend
xhd   |   We have carefully selected several similar problems for you:  1085 1171 1398 2152 2110 
 
从题目中可以看出来,取m件物品可能取到重复的物品,所以这是一个指数型母函数问题
接下来就是套用母函数模板了
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iterator>
#include <iostream>
#include <algorithm>
#define debug(a) cout << #a << " " << a << endl
using namespace std;
const int maxn = 2*1e2 + 10;
const int mod = 10000;
typedef long long ll;
ll f( ll x ) {
ll sum = 1;
for( ll i = 1; i <= x; i ++ ) {
sum *= i;
}
return sum;
}
int main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
ll n, m, num[maxn];
double a[maxn], b[maxn];
while( cin >> n >> m ) {
memset( a, 0, sizeof(a) );
memset( b, 0, sizeof(b) );
for( ll i = 0; i < n; i ++ ) {
cin >> num[i];
}
for( ll i = 0; i <= num[0]; i ++ ) {
a[i] = 1.0/f(i);
}
for( ll i = 1; i < n; i ++ ) {
for( ll j = 0; j <= n; j ++ ) {
for( ll k = 0; k <= num[i] && k+j <= n; k ++ ) {
b[k+j] += a[j]/f(k);
}
}
for( ll j = 0; j <= n; j ++ ) {
a[j] = b[j], b[j] = 0;
}
}
printf("%.lf\n",a[m]*f(m) );
}
return 0;
}

  

hdu1521 排列组合 指数型母函数模板题的更多相关文章

  1. hdu1521 排列组合(指数型母函数)

    题意: 有n种物品,并且知道每种物品的数量ki.要求从中选出m件物品的排数.         (全题文末) 知识点: 普通母函数 指数型母函数:(用来求解多重集的排列问题) n个元素,其中a1,a2, ...

  2. hdu1521:排列组合---指数型母函数

    题意: n种元素,每种有 ni个,选出 m 个的排列有多少种 题解: 指数型母函数的裸题 x^n 项的系数为  an/n!.... 代码如下: #include <iostream> #i ...

  3. HDU 1521 排列组合 指数型母函数

    排列组合 Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit Status D ...

  4. HDU 2079 选课时间(母函数模板题)

    链接:传送门 思路:母函数模板题 /************************************************************************* > Fil ...

  5. 【指数型母函数】hdu1521 排列组合

    #include<cstdio> #include<cstring> using namespace std; int n,m,jiecheng[11]; double a[1 ...

  6. HDU2082母函数模板题

    找单词 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  7. HDU 1521 排列组合 (母函数)

    题目链接 Problem Description 有n种物品,并且知道每种物品的数量.要求从中选出m件物品的排列数.例如有两种物品A,B,并且数量都是1,从中选2件物品,则排列有"AB&qu ...

  8. HDU 2082 母函数模板题

    找单词 Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit Status De ...

  9. HDU1028 Ignatius and the Princess III 【母函数模板题】

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

随机推荐

  1. UE4 打包详细流程

    这两天试着把之前做的一个UE4项目在安卓机上运行下,于是乎有了下面的一个打包血泪史. 首先呢,肯定是下载好了UE的源码了,我用的是4.18. 安装步骤可以先参考下官方的教程http://api.unr ...

  2. __int64与long long、long的区别

    首先来看一看int.long.long long的取值范围 int                  所占字节数为:4                   表示范围为:-2147483648~2147 ...

  3. logback使用配置

    一:logback.xml配置内容如下 <?xml version="1.0" encoding="UTF-8"?> <!-- Copyrig ...

  4. 深入理解JVM-java字节码文件结构剖析(1)

    public class MyTest1 { private int a = 1; public int getA() { return a; } public void setA(int a) { ...

  5. Unity经典游戏教程之:弓之骑士

    版权声明: 本文原创发布于博客园"优梦创客"的博客空间(网址:http://www.cnblogs.com/raymondking123/)以及微信公众号"优梦创客&qu ...

  6. redis实现排行榜

    1 前言 实现一个排版榜,我们通常想到的就是mysql的order by 简单粗暴就撸出来了.但是这样真的优雅吗? 数据库是系统的瓶颈,这是众所周知的.如果给你一张百万的表,让你排序做排行榜,花费的时 ...

  7. 关于修改主机名和ssh免密登录

    修改主机名的常规方法: 1.hostname name2.echo name  > /proc/sys/kernel/hostname3.sysctl kernel.hostname=name4 ...

  8. exe、dos、bat等静默运行,后台运行,不弹窗的解决办法

    exe中 #pragma comment( linker, "/subsystem:windows /entry:mainCRTStartup" ) 1. WinExec(LPCS ...

  9. c语言实现基本的数据结构(六) 串

    #include <stdio.h> #include <tchar.h> #include <stdlib.h> // TODO: 在此处引用程序需要的其他头文件 ...

  10. Mybatis框架(8)---Mybatis插件原理

    Mybatis插件原理 在实际开发过程中,我们经常使用的Mybaits插件就是分页插件了,通过分页插件我们可以在不用写count语句和limit的情况下就可以获取分页后的数据,给我们开发带来很大 的便 ...