The King’s Ups and Downs
有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的更多相关文章
- 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). ...
- 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 ...
- 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 ...
- 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 ...
- HDU 4489 The King’s Ups and Downs (DP+数学计数)
题意:给你n个身高高低不同的士兵.问你把他们按照波浪状排列(高低高或低高低)有多少方法数. 析:这是一个DP题是很明显的,因为你暴力的话,一定会超时,应该在第15个时,就过不去了,所以这是一个DP计数 ...
- HDU 4489 The King’s Ups and Downs
http://acm.hdu.edu.cn/showproblem.php?pid=4489 题意:有n个身高不同的人,计算高低或低高交错排列的方法数. 思路:可以按照身高顺序依次插进去. d[i][ ...
- HDU 4055 The King’s Ups and Downs(DP计数)
题意: 国王的士兵有n个,每个人的身高都不同,国王要将他们排列,必须一高一矮间隔进行,即其中的一个人必须同时高于(或低于)左边和右边.问可能的排列数.例子有1千个,但是最多只算到20个士兵,并且20个 ...
- The King’s Ups and Downs(HDU 4489,动态规划递推,组合数,国王的游戏)
题意: 给一个数字n,让1到n的所有数都以波浪形排序,即任意两个相邻的数都是一高一低或者一低一高 比如:1324 4231,再比如4213就是错的,因为4高,2低,接下来1就应该比2高,但是它没有 ...
- 【转载】ACM总结——dp专辑
感谢博主—— http://blog.csdn.net/cc_again?viewmode=list ---------- Accagain 2014年5月15日 动态规划一 ...
随机推荐
- LeetCode:访问所有节点的最短路径【847】
LeetCode:访问所有节点的最短路径[847] 题目描述 给出 graph 为有 N 个节点(编号为 0, 1, 2, ..., N-1)的无向连通图. graph.length = N,且只有节 ...
- leetcode 859. Buddy Strings
Given two strings A and B of lowercase letters, return true if and only if we can swap two letters i ...
- Android Weekly Notes Issue #320
Android Weekly Issue #320 July 29th, 2018 Android Weekly Issue #320 本期内容包括: Firebase的MLKit; 关于写Andro ...
- <关于J2EE环境的搭建>在Fedora21下的Tomcat,Mysql,jdk以及Intellij的搭建过程
题外话:一开始很不情愿写这种没有技术含量的博文,但是网上对于fedora21下的整个J2EE环境的搭建过程的文章实在是少之又少,那我就破个例吧:-p (一)JDK的下载及环境变量的设置 如果你对JDK ...
- CodeForces - 922E Birds —— DP
题目链接:https://vjudge.net/problem/CodeForces-922E E. Birds time limit per test 1 second memory limit p ...
- 算法(Algorithms)第4版 练习 1.3.13
(a) 0 1 2 3 4 5 6 7 8 9 (b) 4 6 8 7 5 3 2 9 0 1 (c) 2 5 6 7 4 8 9 3 1 0 (d) 4 3 2 1 0 5 6 7 8 9 答案:b ...
- 杂草丛生HTML5网站模板
杂草丛生HTML5个人网站模板是一款野草到处生长的HTML5网站模板下载. 模板地址:http://www.huiyi8.com/sc/8780.html
- H5内容安全尺寸
设备独立像素:iPhone5:320 * 568 >> 微信网页可视区高度:504px iPhone6:375 * 667 >> 微信网页可视区高度:603px 设备独立像 ...
- python 之生成器
斐波拉契数列: In [31]: def func(times): ...: alist = [0,1] ...: sum = 0 ...: for i in range(times): ...: . ...
- 关于STM32中GPIO的8种工作模式
CSDN:http://blog.csdn.net/l20130316 博客园:http://www.cnblogs.com/luckyalan/ 1 综述 I/O口是单片机中非常常用的外设,STM3 ...