POJ 2279 Mr. Young's Picture Permutations

2279
思路:钩子公式
代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
#define ll long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head

const int N = 10;
int a[N], gouzi[N*N], n, cnt;
int main() {
    while(~scanf("%d", &n) && n) {
        for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
        cnt = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= a[i]; ++j){
                gouzi[++cnt] = a[i]-j+1;
                for (int k = i+1; k <= n; ++k) {
                    if(a[k] >= j)gouzi[cnt]++;
                    else break;
                }
            }
        }
        LL x = 1, y = 1;
        sort(gouzi+1, gouzi+1+cnt, greater<int>());
        for (int i = cnt; i >= 1; --i) {
            x *= i;
            y *= gouzi[i];
            gouzi[i] = 0;
            LL t = __gcd(x, y);
            x /= t;
            y /= t;
        }
        printf("%lld\n", x/y);
    }
    return 0;
}

posted @ 2019-09-30 16:45  Wisdom+.+  阅读(171)  评论(0编辑  收藏  举报