hdu 1521 排列组合

简单的指数型母函数!!!

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<vector>
#include<stdlib.h>
using namespace std;
double
a[1001],b[1001],p[1002],s[110];
void
init(){
    s[0]=s[1]=1;
    for
(int i=2; i<=10; i++){
        s[i] = i * s[i-1];
    }
}

int
main()
{

    int
i,j,k,n,m;
    init();
    while
(scanf("%d%d",&n,&m)!=EOF){
        for
(i=1;i<=n;i++){
            cin>>p[i];
        }

        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        for
(i=0;i<=p[1];i++)
            a[i]=1.0/s[i];
        for
(i=2;i<=n;i++){
            for
(j=0;j<=10;j++)
                for
(k=0;k+j<=10&&k<=p[i];k++){
                    b[j+k]+=a[j]/s[k];
                }

            for
(j=0;j<=10;j++){
                a[j]=b[j];
                b[j]=0;
            }
        }

        cout<<fixed<<setprecision(0)<<a[m]*s[m]<<endl;
    }

    return
0;
}

posted @ 2013-07-25 12:17  _随心所欲_  阅读(154)  评论(0编辑  收藏  举报