UVA 1638 Pole Arrangement

#include<bits/stdc++.h>
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<algorithm>
#include<stack>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
ll d[21][21][21];
ll f(int i,int j,int k)
{
    //cout<<i<<" "<<j<<" "<<k<<endl;
    if(d[i][j][k]!=0)return d[i][j][k];
    if(i<=0||j<=0||k<=0)return 0;
    if(i==1)
    {
        if(j==1&&k==1)return d[i][j][k]=1;
        else return d[i][j][k]=0;
    }
    if(j>i||k>i)return 0;
    return d[i][j][k]=f(i-1,j-1,k)+f(i-1,j,k-1)+f(i-1,j,k)*(i-2);
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
#endif // ONLIN
    int t;
    cin>>t;
    int i,j,k;
    while(t--)
    {
        cin>>i>>j>>k;
        ll ans=f(i,j,k);
        cout<<ans<<endl;
    }
}

 

posted @ 2018-08-24 14:45  erge1998  阅读(123)  评论(0编辑  收藏  举报