Uva 1638 Pole Arrangement DP


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


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        :CKboss
Created 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值