有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. 我的Android进阶之旅------>温习Sqlite3的常用操作

    前言;今天要写一个应用来调节系统的Brightness值,来改变系统的背光亮度.由于刚开始些的时候没有考虑Brightness的最小值,直接托动SeekBar到最小值(为0).瞬间,屏幕变成全黑,失败 ...

  2. Django 初始化数据库

    django 初始化数据库 刷新数据库guoguos-MacBook-Pro:mysite guoguo$ python manage.py sqlflushBEGIN;SET FOREIGN_KEY ...

  3. redux和mobx比较(一)

    Redux vs Mobx 那么具体到这两种模型,又有一些特定的优缺点呈现出来,先谈谈 Redux 的优势: 数据流流动很自然,因为任何 dispatch 都会导致广播,需要依据对象引用是否变化来控制 ...

  4. Java for LeetCode 114 Flatten Binary Tree to Linked List

    Given a binary tree, flatten it to a linked list in-place. For example, Given 1 / \ 2 5 / \ \ 3 4 6 ...

  5. linux撤销命令

    u撤销上一步操作 ctrl+r恢复上一步被撤销的操作

  6. java.lang.UnsupportedClassVersionError: com/dw/Function : Unsupported major.minor version 52.0

    本地环境中有jdk7和jdk8,当把jdk8改为jdk7时,出现如下错误,是jdk版本的问题,在Properties-->JAVA Compiler-中的Compiler compliance ...

  7. 3D立方体旋转动画

    在线演示 本地下载

  8. ESP8266串口模块的基本使用【转】

    本文转载自:http://www.shaoguoji.cn/2017/01/15/ESP8266-usage/ ESP8266是一款超低功耗的UART-WiFi 透传模块,拥有业内极富竞争力的封装尺寸 ...

  9. JS高级调试技巧:捕获和分析 JavaScript Error详解

    前端工程师都知道 JavaScript 有基本的异常处理能力.我们可以 throw new Error(),浏览器也会在我们调用 API 出错时抛出异常.但估计绝大多数前端工程师都没考虑过收集这些异常 ...

  10. ss命令能识别的TCP状态的关键字

    [TCP_ESTABLISHED] = "ESTAB",         [TCP_SYN_SENT] = "SYN-SENT",         [TCP_S ...