有n个高矮不同的士兵,现在要将他们按高,矮依次排列,问有多少种情况。

化简为 n个人,求出可以形成波浪形状的方法数

#include <iostream>
#include <cmath>
#include <math.h>
#include <vector>
#include <cstdio>
#include <cstring> #include <algorithm>
#define ll long long
using namespace std;
ll dp[][];
ll sum[];
ll C(ll x,ll y)
{
ll ans = ;
if(x < y)
return ;
else if(x == y || y ==)
return ;
else{
for(ll i=x;i>=(x-y+);--i){
ans *= i;
}
while(y){
ans /= y--;
}
return ans;
}
}
void f()
{
sum[] = ;
sum[] = ;
dp[][] = dp[][] = ;
dp[][] = dp[][] = ;
dp[][] = dp[][] = ; for(int i=;i<=;i++)
{
for(int j=;j<i;j++)
{
sum[i] += dp[j][]*dp[i-j-][]*C(i-,j);
}
dp[i][] = dp[i][] = sum[i]/;
}
} int main()
{
memset(dp,,sizeof(dp));
memset(sum,,sizeof(sum));
f();
int n,m,p;
cin>>n;
while(n--)
{
cin>>m>>p;
cout<<m<<" "<<sum[p]<<endl;
}
return ;
}

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. 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 ...

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

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

  6. HDU 4489 The King’s Ups and Downs

    http://acm.hdu.edu.cn/showproblem.php?pid=4489 题意:有n个身高不同的人,计算高低或低高交错排列的方法数. 思路:可以按照身高顺序依次插进去. d[i][ ...

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

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

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

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

  9. 【转载】ACM总结——dp专辑

    感谢博主——      http://blog.csdn.net/cc_again?viewmode=list       ----------  Accagain  2014年5月15日 动态规划一 ...

随机推荐

  1. SecureCRT连接VMWare中Linux

    SecureCRT连接vmvare虚拟机ubuntu的前提条件1.   使用主机可以ping通虚拟机,或虚拟机可以ping通主机2.   虚拟机已经开启ssh服务,可以使用sudo apt-get i ...

  2. P3968 [TJOI2014]电源插排

    P3968 [TJOI2014]电源插排 线段树维护最长空区间及左端点位置,这个和$nlongn$的动态最大子序和差不多,就不多解释了 $n$较大哈希优化空间 My complete code: #i ...

  3. Matlab图像处理(03)-基本概念

    概念定义 动态范围:灰度跨跃的值域称为动态范围.上限取决于饱和度,下限取决于噪声. 对比度:一幅图像中最高和最低灰度级间的灰度差. 空间分辨率:图像中可辨别的最小细节的度量.常用度量每单位距离线对数和 ...

  4. hihocoder hiho第38周: 二分·二分答案 (二分搜索算法应用:二分搜索值+bfs判断可行性 )

    题目1 : 二分·二分答案 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 在上一回和上上回里我们知道Nettle在玩<艦これ>,Nettle在整理好舰队之后 ...

  5. windows下的git使用指令

    经常使用mac和linux 这次使用window开发了一些小项目 废话不多说: git init git add . git commit -m 'note' git remote add origi ...

  6. Python成长之路第一篇(2)__初识列表和元组

    可以将列表和元组当成普通的“数组”,他能保存任意数量任意类型的Python对象,和数组一样都是通过数字0索引访问元素,列表和元组可以存储不同类型的对象,列表和元组有几处重要区别.列表元素用([])包括 ...

  7. linux应用之bugfree的安装及配置

    Bugfree3.0.4 Linux环境安装指南 bugfree系统安装的前提是,配置LAMP环境(apache+mysql+php),下面以centos6.3系统为例介绍bugfree3.0.4的安 ...

  8. POJ3468 A Simple Problem with Integers(数状数组||区间修改的RMQ问题)

    You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of op ...

  9. python之系统编程 --进程

    1.调试(PDB) 代码: [root@master gaoji]# vim test2.py 1 #!/usr/local/bin/python3 2 # -*- coding:utf-8 -*- ...

  10. poj2955——括号匹配

    题目:http://poj.org/problem?id=2955 区间DP. 代码如下: #include<iostream> #include<cstdio> #inclu ...