排列组合

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;
}

  

最新文章

  1. GridView,Repeater增加自动序号列
  2. java Servlet小结
  3. diary and html 文本颜色编辑,行距和其它编辑总汇
  4. 设计模式 - 策略模式(Strategy Pattern) 具体解释
  5. html+css布局小练习w3cfuns
  6. linux kernel中timer的使用
  7. Widget小组件
  8. 第6组UI组件:ViewAnimator及其子类
  9. python 日期 &amp; 时间
  10. Jmeter之分布式测试
  11. asp.net ajax get 调用(和post不一样,直接返回json才行,否则报错;post不能返回json)
  12. ECharts使用—折线图动态加载
  13. 危险代码:如何使用Unsafe操作内存中的Java类和对象
  14. requery.js使用姿势
  15. 第十一章&#160;串 (b2)蛮力匹配
  16. 20175310 《Java程序设计》第1周学习总结(2)
  17. 【转】MySQL安全配置介绍
  18. 终于在nowcoder爆发了的懒惰
  19. 学习Spring Boot:(七)集成Mybatis
  20. Spring RestTemplate 小结

热门文章

  1. 使用verilog编写锁存器与触发器
  2. Extjs的文件上传问题
  3. maven-assembly-plugin 进行打包
  4. ipv6的连接
  5. node命令行工具之实现项目工程自动初始化的标准流程
  6. ASP.NET Core MVC 之依赖注入 Controller
  7. Laya 中缩放的实现
  8. Java 内存模型和 JVM 内存结构真不是一回事
  9. Eclipse导入spring-boot-plus(三)
  10. Nginx安装之源码安装