Uva 1638 Pole Arrangement DP

来源:互联网 发布:火炮兰捏脸数据2016 编辑:程序博客网 时间:2024/05/20 05:47


倒过来从插入最短的木棒考虑


1638 Pole ArrangementThere are poles of height 1, 2, . . . , n in a row. If you look at these poles from the left side or the rightside, smaller poles are hidden by taller poles. For example, consider the two arrangements of 4 poles inthe next figure:For each arrangement, only one pole can be seen from the left, and two poles can be seen from theright.You are to write a program to calculate the number of arrangements of n poles such that seen fromthe left you see l poles and seen from the right you see r poles.InputYour program is to read from standard input. The input consists of T test cases. The number of testcases T is given in the first line of the input. Each test case consists of a line containing three integers,n, l, and r (1 ≤ l, r ≤ n ≤ 20), where n is the number of poles and l (resp. r) is the number of polesthat can be seen from the left (resp. right).OutputYour program is to write to standard output. Print exactly one line for each test case. The line shouldcontain the number of arrangements of poles for the test case.The following shows sample input and output for four test cases.Sample Input44 1 24 1 15 2 420 2 1Sample Output2046402373705728000


/* ***********************************************Author        :CKbossCreated Time  :2015年01月29日 星期四 14时51分47秒File Name     :UVA1638.cpp************************************************ */#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <string>#include <cmath>#include <cstdlib>#include <vector>#include <queue>#include <set>#include <map>using namespace std;typedef long long int LL;int n,l,r;LL dp[30][30][30];void init(){dp[1][1][1]=1;for(int i=2;i<=20;i++)for(int j=1;j<=20;j++)for(int k=1;k<=20;k++)dp[i][j][k]=dp[i-1][j-1][k]+dp[i-1][j][k-1]+(i-2)*dp[i-1][j][k];}int main(){    //freopen("in.txt","r",stdin);    //freopen("out.txt","w",stdout);    int T_T;scanf("%d",&T_T);init();while(T_T--){scanf("%d%d%d",&n,&l,&r);cout<<dp[n][l][r]<<endl;}    return 0;}


0 0