zoukankan      html  css  js  c++  java
  • Hdu 1521 排列组合

       a1 n1 
    a2 n2
    ...
    ak nk
    n=n1+n2+...+nk
    从n个数中选r个排列(不是组合噢)
    // 指数型母函数
    // 模板
    #include <iostream> #include <string> #include<sstream> #include <cmath> #include <map> #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; #define LL __int64//long long struct node { LL u,d; // u/d node(){} node(LL a,LL b){ u=a; d=b; } LL gcd(LL a,LL b) { LL r; while(r=a%b){a=b;b=r;} return b; } node operator +(node no) { LL da=gcd(d,no.d); LL son=no.d/da*u+d/da*no.u; LL mather=no.d/da*d; da=gcd(son,mather); return node(son/da,mather/da); } }Ge[22],tp[22]; LL f[22]; int main() { int i,j,k; f[1]=1; for(i=2;i<=10;i++) f[i]=f[i-1]*i; int n,m; while(scanf("%d %d",&n,&m)!=EOF) { // memset(Ge,0,sizeof(Ge)); Ge[0].u=Ge[0].d=1; for(i=1;i<=m;i++) Ge[i].u=0,Ge[i].d=1; for(i=1;i<=m;i++) tp[i].u=0,tp[i].d=1; while(n--) { scanf("%d",&k); // memset(tp,0,sizeof(tp)); for(i=1;i<=k&&i<=m;i++) for(j=0;j+i<=m;j++) { tp[i+j]=tp[i+j]+ node(Ge[j].u,Ge[j].d*f[i]); //printf("%I64d %I64d ",tp[i].u,tp[i].d); } for(i=1;i<=m;i++) Ge[i]=tp[i];//printf("%I64d %I64d ",Ge[i].u,Ge[i].d), } printf("%I64d ",f[m]/Ge[m].d*Ge[m].u);//f[m]*Ge[m].u); } return 0; }
  • 相关阅读:
    [COGS2580]偏序 II
    [COGS2479]偏序
    [BZOJ2716]天使玩偶
    [BZOJ4237]稻草人/[JOISC2014]かかし
    Ynoi2015 世上最幸福的女孩
    ARC098D Donation
    BZOJ3691 游行
    CF923E Perpetual Subtraction
    Luogu P4191 [CTSC2010]性能优化
    Topcoder SRM 590 Fox And City
  • 原文地址:https://www.cnblogs.com/372465774y/p/3604822.html
Copyright © 2011-2022 走看看