码迷,mamicode.com
首页 > 其他好文 > 详细

Uva 1638 Pole Arrangement DP

时间:2015-01-29 17:44:49      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:


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


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;
}


Uva 1638 Pole Arrangement DP

标签:

原文地址:http://blog.csdn.net/ck_boss/article/details/43272919

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!