HDU 1521 排列组合
来源:互联网 发布:知乎 微星台式机 编辑:程序博客网 时间:2024/05/29 07:38
HDU 1521 排列组合
题意:
(中文)
思路:
此题是一道指数型母函数的题目,
G(x) = (1 + x / 1! + x^2 / 2! + x^3 / 3! + …. + x^n1 / n1!)
* (1 + x / 1 ! + x^2 / 2! + … + x^n2 / n2!) * …
* (1 + x / 1! + x^2 / 2! + .. + x^nk / nk!).
先把阶层求出来,当计算的时候每次都除f[n],在最后还原系数的时候再乘上去。
Code:
#include<cstdio>#include<cstdlib>#include<cstring>#include<cctype>#include<cmath>#include<algorithm>#include<iostream>#include<string>#include<vector>#include<bitset>#include<queue>#include<stack>#include<list>#include<map>#include<set>#define TEST#define LL long long#define Mt(f, x) memset(f, x, sizeof(f));#define rep(i, s, e) for(int i = (s); i <= (e); ++i)#ifdef TEST #define See(a) cout << #a << " = " << a << endl; #define See2(a, b) cout << #a << " = " << a << ' ' << #b << " = " << b << endl; #define debug(a, s, e) rep(_i, s, e) {cout << a[_i] << ' ';} cout << endl; #define debug2(a, s, e, ss, ee) rep(i_, s, e) {debug(a[i_], ss, ee)}#else #define See(a) #define See2(a, b) #define debug(a, s, e) #define debug2(a, s, e, ss, ee)#endif // TESTconst int MAX = 2e9;const int MIN = -2e9;const double eps = 1e-8;const double PI = acos(-1.0);using namespace std;const int N = 100;int f[N];int a[N];double c1[N], c2[N];void init(){ f[0] = 1; for(int i = 1; i <= 13; ++i) { f[i] = f[i - 1] * i; }}int main(){ int n, m; init(); while(~scanf("%d%d", &n, &m)) { for(int i = 1; i <= n; ++i) { scanf("%d", &a[i]); } Mt(c1, 0); Mt(c2, 0); c1[0] = 1; for(int i = 1; i <= n; ++i) { for(int k = 0; k <= a[i]; ++k) { for(int s = 0; s + k <= m; ++s) { c2[s + k] += c1[s] / f[k]; } } for(int k = 0; k <= m; ++k) { c1[k] = c2[k]; c2[k] = 0; } } printf("%.0f\n", c1[m] * f[m]); } return 0;}
0 0
- hdu 1521 排列组合
- HDU 1521 排列组合
- hdu 1521 排列组合
- hdu 1521 排列组合 组合
- HDU 1521 排列组合
- HDU 1521排列组合
- HDU's ACM 1521 排列组合
- hdu(1521)——排列组合
- 母函数 HDU 1521 排列组合
- HDU 1521 排列组合(指数型母函数)
- HDU 1521 排列组合 指数型母函数
- [ACM] hdu 1521 排列组合(组合+DFS)
- Hdu 1521 排列组合 指数型母函数
- hdu-1521-排列组合(母函数)
- hdu 1521 排列组合(指数型母函数)
- 指数型母函数:hdu 1521 排列组合
- [HDU 1521] 排列组合 指数型母函数
- HDU 1521 排列组合(指数型母函数)
- 车票找零
- android ndk程序调试方法
- NYOJ_语言入门
- 受不了Android SDK文档打开缓慢问题,自己开发简易脱机浏览器。
- Matlab-简单练习
- HDU 1521 排列组合
- Volley的使用
- ArrayList的实现原理
- Activity之间过度动画:overridePendingTransition的简介
- JQuery实例总结一
- NYOJ 题目303 序号互换(水)
- Java设计模式——单例模式(Singleton)
- CEPH 框架
- JDK6的Random和System.nanoTime()引起的一个“大”bug