有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. Hadoop实战-Flume之自定义Source(十八)

    import java.nio.charset.Charset; import java.util.HashMap; import java.util.Random; import org.apach ...

  2. eclipse 安装tomcat

  3. 单元測试中 Right-BICEP 和 CORRECT

    My Blog:http://www.outflush.com/ 在单元測试中,有6个总结出的值得測试的方面,这6个方面统称为 Right-BICEP.通过这6个方面的指导.能够较全然的測试出代码中的 ...

  4. 统一ID服务

    代码已经修改 调用方式 为restful请求  或者 feign请求  请参考 wiki:   http://192.168.120.46:8090/display/peixun/akucun+Gui ...

  5. VC DLL方法的__declspec导入导出

    https://msdn.microsoft.com/zh-cn/library/a90k134d.aspx https://msdn.microsoft.com/zh-cn/library/ms23 ...

  6. 迁移博客到Github Pages

    由于种种原因,我的博客迁移到了 https://phuker.github.io/ .虽然没有多少人气,但是希望能继续见证一个技术渣的成长.

  7. 2013各大IT公司薪资标准

    以此鼓励自己 :http://jinhua.19lou.com/forum-874-thread-115901362964023509-1-1.html   以下三个是老大级别的公司   [微软] 研 ...

  8. 分享知识-快乐自己:Excel快速导入Oracle 数据库

    需求: oracle 数据库有一个student表,现有一个excel表:student.xlsx,需导入oracle数据库student表中. student表的拥有者是c##MLQ1  密码为:x ...

  9. 使用谷歌浏览器进行Web开发技巧

    1.为了避免缓存影响开发,使用使用那个“Ctrl+Shift+N”进入浏览器的隐身模式

  10. ES索引瘦身 禁用_source后需要设置field store才能获取数据 否则无法显示搜索结果

    在默认情况下,开启_all和_source 这样索引下来,占用空间很大. 根据我们单位的情况,我觉得可以将需要的字段保存在_all中,然后使用IK分词以备查询,其余的字段,则不存储. 并且禁用_sou ...