http://acm.hdu.edu.cn/showproblem.php?pid=4489

题意:
有n个身高不同的人,计算高低或低高交错排列的方法数。

思路:
可以按照身高顺序依次插进去。

d【i】【0】表示i个人以高低结尾的方法数,d【i】【1】表示i个人以低高开头的方法数。

将第i个人插入时,当它左边为j个人的时候,右边就是i-1-j,并且左边必须要以高低结尾,右边必须以低高开头。也就是d【i-1】【0】*d【i-1】【1】。当然了,后面还得再乘c(i-1,j),表示选j个人的方法数。

 #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + ; int n; int c[][];
ll d[maxn][];
ll sum[maxn]; void dp()
{
memset(c,,sizeof(c));
memset(d,,sizeof(d)); for(int i=;i<=;i++)
{
c[i][]=;
for(int j=;j<=i;j++)
c[i][j]=c[i-][j-]+c[i-][j];
} sum[]=;
sum[]=;
d[][]=d[][]=;
d[][]=d[][]=;
d[][]=d[][]=; for(int i=;i<=;i++)
{
sum[i]=;
for(int j=;j<=i;j++)
{
sum[i]+=d[j][]*d[i-j-][]*c[i-][j];
}
d[i][]=d[i][]=sum[i]/;
}
} int main()
{
//freopen("in.txt","r",stdin);
int T;
int kase;
scanf("%d",&T);
dp();
while(T--)
{
scanf("%d%d",&kase, &n);
printf("%d %lld\n",kase,sum[n]);
}
return ;
}

HDU 4489 The King’s Ups and Downs的更多相关文章

  1. HDU 4489 The King's Ups and Downs

    HDU 4489 The King's Ups and Downs 思路: 状态:dp[i]表示i个数的方案数. 转移方程:dp[n]=∑dp[j-1]/2*dp[n-j]/2*C(n-1,j-1). ...

  2. HDU 4489 The King’s Ups and Downs dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4489 The King's Ups and Downs Time Limit: 2000/1000 ...

  3. hdu 4489 The King’s Ups and Downs(基础dp)

    The King’s Ups and Downs Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java ...

  4. HDU 4489 The King’s Ups and Downs (DP+数学计数)

    题意:给你n个身高高低不同的士兵.问你把他们按照波浪状排列(高低高或低高低)有多少方法数. 析:这是一个DP题是很明显的,因为你暴力的话,一定会超时,应该在第15个时,就过不去了,所以这是一个DP计数 ...

  5. HDU 4055 The King’s Ups and Downs(DP计数)

    题意: 国王的士兵有n个,每个人的身高都不同,国王要将他们排列,必须一高一矮间隔进行,即其中的一个人必须同时高于(或低于)左边和右边.问可能的排列数.例子有1千个,但是最多只算到20个士兵,并且20个 ...

  6. UVALive 6177 The King's Ups and Downs

    The King's Ups and Downs Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UV ...

  7. The King’s Ups and Downs(HDU 4489,动态规划递推,组合数,国王的游戏)

    题意: 给一个数字n,让1到n的所有数都以波浪形排序,即任意两个相邻的数都是一高一低或者一低一高 比如:1324   4231,再比如4213就是错的,因为4高,2低,接下来1就应该比2高,但是它没有 ...

  8. The King’s Ups and Downs

    有n个高矮不同的士兵,现在要将他们按高,矮依次排列,问有多少种情况. 化简为 n个人,求出可以形成波浪形状的方法数 #include <iostream> #include <cma ...

  9. hdu 4055 && hdu 4489 动态规划

    hdu 4055: 一开始我想的递推方向想得很复杂,看了别人的博客后才醍醐灌顶: 参照他的思路和代码: #include<cstdio> #include<cstring> # ...

随机推荐

  1. SNMP信息泄露漏洞

    SNMP协议简介 名称:SNMP(Simple Network Management Protocol)简单网络管理协议 端口:161 协议:UDP 用途:SNMP代理者以变量呈现管理资料.管理系统透 ...

  2. ipmi监控主机

    author: headsen   chen date: 2018-09-25  20:04:01 IPMI介绍       IPMI(Intelligent Platform Management ...

  3. ajax跨域终极解决办法!

    在使用 ajax 的时候,往往需要通过 ajax 跨域请求一些? 但是 XMLHTTPRequest 是不支持跨域的,所以产生了 JSONP 这个东西来解决跨域,当然解决跨域的方式有很多种.... 第 ...

  4. C语言模拟ATM机界面

    虽然是满屏的printf.printf.printf.printf......尴尬 但是一个小项目做下来还是能学习到很多的,有很多小的问题,不是亲自来敲一遍代码,是不会发现的.他的框架,每一个小函数功 ...

  5. U盘安装Win7系统,遇到硬盘鼠标键盘失灵等情况,如何安装U盘中加入USB3.0驱动的支持

    U盘安装系统出现鼠标键盘不能使用,在intel六代处理器平台,安装过程中会出现安装原生镜像不能识别或者鼠标键盘不能使用等情况,可以参考以下方法进行. 风险提示:重装或升级系统会导致系统盘数据丢失,建议 ...

  6. html<input>输入框中各种正则表达式设置

    <%@ page language="java" contentType="text/html; charset=gb2312" pageEncoding ...

  7. 使用colmap进行稠密重建

    colmap应该是目前state-of-art的增量式SFM方案,可以方便的对一系列二维图片进行三维重建 不用对摄像机进行标定,只需要从不同角度对重建场景或物体进行拍摄得到一系列图像作为输入 首先需要 ...

  8. fastBoot使用

    fastBoot使用 作者:李老师,华清远见嵌入式学院讲师. 1.1. 使用Fastboot方式烧写 在安卓手机中Fastboot是一种比Recovery更底层的刷机模式.Fastboot是一种线刷, ...

  9. linux 分卷压缩和合并

      压缩: 可以用任何方式压缩,如tar -czf 分卷: split [OPTION]... [INPUT [PREFIX]]    -b 代表分卷大小, 后面可以加单位,如G,M,K.   如果不 ...

  10. VirtualBox Guest Additions installation

    在使用VirtualBox为CentOS安装增强功能时,输出是: 文本: Verifying archive integrity... All good. Uncompressing VirtualB ...