有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. django 设置静态文件,static 链接

    这篇文章讲的django 静态static 文件设置,还可以,供参考 http://blog.csdn.net/sinat_21302587/article/details/74059078

  2. C# 序列化反序列化 list<>

    public class XMLTest { [Test] public static void Test() { Name1 name = new Name1(); name.Id = " ...

  3. 51Nod 1515 明辨是非 —— 并查集 + 启发式合并

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1515 1515 明辨是非  题目来源: 原创 基准时间限制:1 ...

  4. Maven2与maven1之间的区别

    1. 更快.更简单比起 Maven1 那不急不慢的运行速度,Maven2在速度上有了质的飞跃,甚至与Ant相比也毫不逊色(当然,下载不算).除此之外,"简化工作,使用业界公认的最佳实践&qu ...

  5. leetcode 67. Add Binary (高精度加法)

    Given two binary strings, return their sum (also a binary string). For example,a = "11"b = ...

  6. Linux下的Tomcat JVM 调优

    1. 适用场景 Tomcat 运行过程遇到Caused by: java.lang.OutOfMemoryError: PermGen space或者java.lang.OutOfMemoryErro ...

  7. POJ2155 Matrix(二维树状数组||区间修改单点查询)

    Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the i-th row an ...

  8. <十七>UML核心视图动态视图之时序图

    一:时序图 --->时序图是用于描述按时间顺序排列的对象之间的交互模式. --->它按照参与交互的对象所具有的“生命线”和他们相互发送的消息来显示这些对象. --->时序图包含对象和 ...

  9. 「NOIP2006」「LuoguP1064」 金明的预算方案(分组背包

    题目描述 金明今天很开心,家里购置的新房就要领钥匙了,新房里有一间金明自己专用的很宽敞的房间.更让他高兴的是,妈妈昨天对他说:“你的房间需要购买哪些物品,怎么布置,你说了算,只要不超过NNN元钱就行” ...

  10. mongodb入门-关系型RDMS数据库对比及适用场景

    引言 最近工作接触到了mongodb数据库,记录下个人对其的理解和使用情况.虽然mongodb 出来的时间已经不短,但是相对mysql mssql oracle 这样传统的关系型数据库来说还是比较年轻 ...