HDOJ-1521 排列组合

一道裸的指数型母函数题.

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <climits>
#include <set>

using namespace std;
double c1[15], c2[15];
int num[15], d[15];

int main(){

    //freopen("in.txt", "r", stdin);
    int n, m;

    d[0] = d[1] = 1;
    for(int i = 2; i <= 10; i++)
      d[i] = d[i-1] * i;
    while(cin >> n >> m){

        for(int i = 0; i < n; i++)
          cin >> num[i];
        memset(c1, 0, sizeof(c1));
        memset(c2, 0, sizeof(c2));
        c1[0] = c2[0] = 1.0;

        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){

                for(int h = 1; h <= num[i] && h + j <= m; h++){
                    c2[h+j] += c1[j] / d[h];
                }   
            }
            for(int h = 0; h <= m; h++)
              c1[h] = c2[h];    
        }
        printf("%.0f\n", c1[m]*d[m]);
    }

    return 0;
}

你可能感兴趣的:(HDOJ-1521 排列组合)