递推。

用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. 30款jQuery常用网页焦点图banner图片切换 下载

    1.jquery 图片滚动特效制作 slide 图片类似窗帘式图片滚动 查看演示 2.jquery幻灯片插件带滚动条的圆形立体图片旋转滚动 查看演示 3.jQuery图片层叠旋转类似洗牌翻转图片幻灯片 ...

  2. emulatorarm.exe已停止工作

    今天使用ADT 打开android模拟器突然发现模拟器报错,[emulatorarm.exe已停止工作],昨天还是好好的,不知道为什么,重建新的模拟器还是这样. 解决办法: 更改ram大小为 512M ...

  3. Sql例子Sp_ExecuteSql 带参数

    Declare @i int, @projectCount int ) --参数 ) ) ) ) ) ) --循环变量起始 --得到所有的项目 select @projectCount = count ...

  4. firefox常用扩展、脚本

    1.AutoPopup.uc.js:鼠标移到菜单和下拉箭头上自动弹出下拉菜单 2.moveButton.uc.js:移动或克隆按钮或菜单到火狐浏览器的任意位置 moveButton.uc.js使用说明 ...

  5. 【BZOJ】【1770】【Usaco2009 Nov】lights 灯

    高斯消元解XOR方程组 一眼看上去是高斯消元解xor方程组……但是不会写……sad 去膜拜了Hzwer和ZYF Hzwer啥也没说,还是zyf靠谱…… 当多解的时候就需要爆搜枚举自由元的情况,找最优解 ...

  6. 【BZOJ】【1965】SHUFFLE 洗牌

    扩展欧几里德+快速幂 每次转换位置:第x位的转移到2*x %(n+1)这个位置上 那么m次后就到了(2^m)*x %(n+1)这个位置上 那么找洗牌m次后在 l 位置上的牌就相当于解线性模方程: (2 ...

  7. [转载]C# Double toString保留小数点方法

    有时候double型数据需要toString(),但又想保留小数,当值为整数,比如3.00时tostring后会变为”3″,具体说明见下: 1 string str0 = i.ToString(&qu ...

  8. C && C++ 内存分配示意图

    <Unix环境系统高级编程>中的C语言内存分布示意图 1.C内存分布 BSS段: 用来存放程序中未初始化的全局变量.BSS是英文Block Started by Symbol的简称.BSS ...

  9. _beginthreadex创建多线程详解

    一.需要的头文件支持 #include <process.h>         // for _beginthread() 需要的设置:ProjectSetting-->C/C++- ...

  10. POJ 1915

    #include<iostream> #include<stdio.h> #define MAXN 350 #include"queue" using na ...