递推。

用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. Asp.net弹出层并且有遮罩层

    长久以来,asp.net弹出层并且有遮罩层问题都是一个难以解决的问题,鉴于此,我决定写个弹出层发布出来,供大家使用... 这里的doing层是遮罩层,divLogin层是登陆层 若有其他问题请留言或邮 ...

  2. 一点ASP.NET MVC Html.Helper类的方法

    一点ASP.NET MVC Html.Helper类 这里就只写一个Html.ActionLink()和Html.DropdownList(). Html.ActionLink()里有三个参数,第一个 ...

  3. UML: CIM & PIM

    CIM-1:定义业务流程 定义及分析业务流程(Business Process)是为了尽快理清系统范围,以便估算开发成本及时间,可不是为了要改造业务流程.系统分析员千万别误解了此步骤的目的.所以,系统 ...

  4. java,图片压缩,略缩图

    在网上找了两个图片的缩放类,在这里分享一下: package manager.util; import java.util.Calendar; import java.io.File; import ...

  5. SqlServer 系统存储过程

    exec sp_databases; --查看数据库exec sp_tables; --查看表exec sp_columns Categories;--查看列exec sp_helpIndex Cat ...

  6. 【POJ】【3308】Paratroopers

    网络流/二分图最小点权覆盖 sigh……这题……TLE&RE了好几发 建一个二分图,左边的每个结点代表行,右边的代表列,如果在(i,j)这个位置有一个外星人,那么我们就连一条边 (左 i -& ...

  7. Unity3D 游戏开发构架篇 —— 动态大场景生成 = 区域加载+对象池管理

    项目做一个类似无尽模式的场景,想了一想,其实方法很简单,做一个相关的总结. 主要先谈一谈构架,后期附上代码. 一.区域加载 其实无尽场景的实现很简单,因为屏幕限制,那么不论何时何地,我们只能看到自己的 ...

  8. linux源码阅读笔记 void 指针

    void 指针的步长为1,而其他类型的指针的步长与其所定义的数据结构有关. example: 1 #include<stdio.h> 2 main() 3 { 4 int a[10]; 5 ...

  9. docker设置代理

    在天朝使用docker需要FQ. 下面给出docker的代理方式: HTTP_PROXY=http://10.167.251.83:8080 docker -d

  10. Chp5: Bit Manipulation

    Bits Facts and Tricks x ^ 0s =  x x & 0s =  0 x | 0s = x x ^ 1s = ~x x & 1s = x x | 1s = 1s ...