递推。

用f[n][l][r]表示n个柱子,从左面能看到l个,从右面能看到r个。

如果我们按照从小到大的顺序放置的话,放置最高的柱子后,大量状态都能递推到当前状态,很难写出递推式。

但是我们如果从小到大放置的话,高度为1的柱子放进去只会产生3种不同的情况。

1.最左面.2.中间。3.右面

在中间的哪里是无所谓的。

所以f[i][j][k]=f[i-1][j-1][k]+f[i-1][j][k-1]+(i-2)*f[i-1][l][r]。

边界条件 f[1][1][1]=1。

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define LL long long
const int maxn = 20 + 10; LL f[maxn][maxn][maxn];
int n=20,l,r; void init() {
f[1][1][1]=1;
for(int i=2;i<=n;i++) {
for(int l=1;l<=n;l++)
for(int r=1;r<=n;r++) {
if(l+r>i+1) break;
f[i][l][r]=f[i-1][l-1][r]+f[i-1][l][r-1]+f[i-1][l][r]*(i-2);
}
}
} int main() {
int T;
init();
scanf("%d",&T);
while(T--) {
scanf("%d%d%d",&n,&l,&r);
printf("%lld\n",f[n][l][r]);
}
return 0;
}

uva1638Pole Arrangement的更多相关文章

  1. [leetcode-526-Beautiful Arrangement]

    Suppose you have N integers from 1 to N. We define a beautiful arrangement as an array that is const ...

  2. zoj3777 Problem Arrangement

    The 11th Zhejiang Provincial Collegiate Programming Contest is coming! As a problem setter, Edward i ...

  3. ZOJ 3777-Problem Arrangement(状压DP)

    B - Problem Arrangement Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %l ...

  4. [LeetCode] Beautiful Arrangement II 优美排列之二

    Given two integers n and k, you need to construct a list which contains n different positive integer ...

  5. [LeetCode] Beautiful Arrangement 优美排列

    Suppose you have N integers from 1 to N. We define a beautiful arrangement as an array that is const ...

  6. [Swift]LeetCode526. 优美的排列 | Beautiful Arrangement

    Suppose you have N integers from 1 to N. We define a beautiful arrangement as an array that is const ...

  7. ZOJ 3777 - Problem Arrangement - [状压DP][第11届浙江省赛B题]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3777 Time Limit: 2 Seconds      Me ...

  8. HDU 3577Fast Arrangement(线段树模板之区间增减更新 区间求和查询)

    Fast Arrangement Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  9. Codeforces 908 D.New Year and Arbitrary Arrangement (概率&期望DP)

    题目链接:New Year and Arbitrary Arrangement 题意: 有一个ab字符串,初始为空. 用Pa/(Pa+Pb)的概率在末尾添加字母a,有 Pb/(Pa+Pb)的概率在末尾 ...

随机推荐

  1. 服务器端spice配置详解

    1. 安装必要的工具 sudo apt-get install build-essential autoconf git-core intltool 2. 安装必要的依赖包 -dev libxfixe ...

  2. C# WPF打印报表

    前天我的一个同学由于打印报表而苦恼,所以就介绍了一下WPF的打印报表,希望能帮助到大家. 展示报表 1. 首先新建项“报表”,选定项目,右击,点击“添加”->“新建项”->“报表”

  3. js遍历集合

    首先,描述一下问题.由于需要后台取出数据,遍历展示在table中,大体如下: 后台取出的是 Map<String , List<Object>>,下面是我写得比较朴素一点的写法 ...

  4. SQLServer 语句-创建索引【转】

    语法:CREATE [索引类型] INDEX 索引名称ON 表名(列名)WITH FILLFACTOR = 填充因子值0~100GO /*实例*/USE 库名GOIF EXISTS (SELECT * ...

  5. c++ 哪些自定义的数据类型

    http://www.cnblogs.com/ShaneZhang/archive/2013/06/21/3147648.html 这些数据类型是 C99 中定义的,具体定义在:/usr/includ ...

  6. shell脚本积累

    统计当前目录下文件夹的大小 for d in $(ls) do du -sh ./$d done 获取之前日期date  +"%Y%m%d" -d  "-n days&q ...

  7. [转载]DateTime TryParse

    今天被Architect问住了,说你光用一个TryParse就判断人家是不是时间日期型的,是不完整的.所以我花点时间看了下TryParse的用法. MSDN:http://msdn.microsoft ...

  8. 1. what is Lua?

    glue language Lua is a proven, robust language, small.

  9. 如何正确学习JavaScript

    不要这样学习JavaScript 不要一开始就埋头在成堆的JavaScript在线教程里 ,这是最糟糕的学习方法.或许在看过无数个教程后会有点成效,但这样不分层次结构地学习一个东西实在是十分低效,在实 ...

  10. *[hackerrank]Sam and sub-strings

    https://www.hackerrank.com/contests/w3/challenges/sam-and-substrings DP.注意到以N[i]结尾的每个字符串的子数字和有规律: 53 ...