递推。

用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. cocos2d-x入门笔记(1)

    cocos2d-x的大致开发流程是,首先使用win32版进行代码编写并完成游戏,然后将代码迁移到对应的开发环境上进行交叉编译完成游戏打包,如iphone上是mac+xcode,android是ecli ...

  2. Careercup - Facebook面试题 - 5412018236424192

    2014-05-01 01:32 题目链接 原题: Given a linked list where apart from the next pointer, every node also has ...

  3. 关于sublime text的配置方法

    一个星期没有写博客了, 是时候来一波了 -------------------------------------------------------------------------------- ...

  4. android禁止ScrollView自动滚动

    当Scrollview嵌套listview,或者子View的内容过多时,当内容加载完成后,ScrollView中内容的长度会发生改变,ScrollView会自动往下滚动,解决办法:在ScollView ...

  5. c++ uuid生成法则

    http://www.jb51.net/LINUXjishu/39614.html CentOS #include <uuid/uuid.h> 找不到文件解决方法: sudo yum in ...

  6. PAT-乙级-1053. 住房空置率 (20)

    1053. 住房空置率 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 在不打扰居民的前提下,统计住房空 ...

  7. UDP TCP 消息边界

    先明确一个问题,如果定义了一个数据结构,大小是,比方说 32 个字节,然后 UDP 客户端连续向服务端发了两个包.现在假设这两个包都已经到达了服务器,那么服务端调用 recvfrom 来接收数据,并且 ...

  8. Android SDK下载地址

    原地址:http://lameck.blog.163.com/blog/static/38811374201262111309677/ Android SDK.ADT.tools等官方下载地址(201 ...

  9. POJ2004 Mix and build Trie树? dp?

    学习Trie树中,所以上网搜一下Trie树的题,找到这个,人家写着是简单dp,那我就想着能学习到什么Trie树上的dp,但最后发现根本好像跟Trie树没有什么联系嘛... 题意就是给你很多个字符串(长 ...

  10. Javascript 中childNodes和children的区别

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...