HDU 4489 The King’s Ups and Downs
http://acm.hdu.edu.cn/showproblem.php?pid=4489
题意:
有n个身高不同的人,计算高低或低高交错排列的方法数。
思路:
可以按照身高顺序依次插进去。
d【i】【0】表示i个人以高低结尾的方法数,d【i】【1】表示i个人以低高开头的方法数。
将第i个人插入时,当它左边为j个人的时候,右边就是i-1-j,并且左边必须要以高低结尾,右边必须以低高开头。也就是d【i-1】【0】*d【i-1】【1】。当然了,后面还得再乘c(i-1,j),表示选j个人的方法数。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + ; int n; int c[][];
ll d[maxn][];
ll sum[maxn]; void dp()
{
memset(c,,sizeof(c));
memset(d,,sizeof(d)); for(int i=;i<=;i++)
{
c[i][]=;
for(int j=;j<=i;j++)
c[i][j]=c[i-][j-]+c[i-][j];
} sum[]=;
sum[]=;
d[][]=d[][]=;
d[][]=d[][]=;
d[][]=d[][]=; for(int i=;i<=;i++)
{
sum[i]=;
for(int j=;j<=i;j++)
{
sum[i]+=d[j][]*d[i-j-][]*c[i-][j];
}
d[i][]=d[i][]=sum[i]/;
}
} int main()
{
//freopen("in.txt","r",stdin);
int T;
int kase;
scanf("%d",&T);
dp();
while(T--)
{
scanf("%d%d",&kase, &n);
printf("%d %lld\n",kase,sum[n]);
}
return ;
}
HDU 4489 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 ...
- HDU 4489 The King’s Ups and Downs (DP+数学计数)
题意:给你n个身高高低不同的士兵.问你把他们按照波浪状排列(高低高或低高低)有多少方法数. 析:这是一个DP题是很明显的,因为你暴力的话,一定会超时,应该在第15个时,就过不去了,所以这是一个DP计数 ...
- HDU 4055 The King’s Ups and Downs(DP计数)
题意: 国王的士兵有n个,每个人的身高都不同,国王要将他们排列,必须一高一矮间隔进行,即其中的一个人必须同时高于(或低于)左边和右边.问可能的排列数.例子有1千个,但是最多只算到20个士兵,并且20个 ...
- 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 ...
- The King’s Ups and Downs(HDU 4489,动态规划递推,组合数,国王的游戏)
题意: 给一个数字n,让1到n的所有数都以波浪形排序,即任意两个相邻的数都是一高一低或者一低一高 比如:1324 4231,再比如4213就是错的,因为4高,2低,接下来1就应该比2高,但是它没有 ...
- The King’s Ups and Downs
有n个高矮不同的士兵,现在要将他们按高,矮依次排列,问有多少种情况. 化简为 n个人,求出可以形成波浪形状的方法数 #include <iostream> #include <cma ...
- hdu 4055 && hdu 4489 动态规划
hdu 4055: 一开始我想的递推方向想得很复杂,看了别人的博客后才醍醐灌顶: 参照他的思路和代码: #include<cstdio> #include<cstring> # ...
随机推荐
- 【BZOJ4285】使者 cdq分治+扫描线+树状数组
[BZOJ4285]使者 Description 公元 8192 年,人类进入星际大航海时代.在不懈的努力之下,人类占领了宇宙中的 n 个行星,并在这些行星之间修建了 n - 1 条星际航道,使得任意 ...
- java.lang.IllegalArgumentException: Invalid character found in the request target.
java.lang.IllegalArgumentException: Invalid character found in the request target. http参数存在特殊字符: 特殊字 ...
- angularJS的路由!
angularJS 路由:(分发需求) angularJS 中路由是单独提供的功能模块,ngRoute 也是一个单独发行的文件 可以通过 npm 去安装这个包:angular-route <s ...
- linux 统计文件数量
查找当前目录下compose文件的数量 ls -lr | grep "compose" | wc -l
- fiddler win10-1703Failed to register Fiddler as the system proxy
正解 The solution for the Fiddler error of "Failed to register Fiddler as the system proxy" ...
- 使用colmap进行稠密重建
colmap应该是目前state-of-art的增量式SFM方案,可以方便的对一系列二维图片进行三维重建 不用对摄像机进行标定,只需要从不同角度对重建场景或物体进行拍摄得到一系列图像作为输入 首先需要 ...
- mysql线上负载高怎么排查
作为一个开发人员或者数据库管理员,学会检查数据库运行情况是必不可少的工作.造成MySQL线程卡顿的原因有很多,但是无论是哪种原因,我们发现问题之后的第一要务就是解决问题,防止问题继续恶化.那么,应该如 ...
- Swap---hdu2819(最大匹配)
题意:通过交换行或者列来实现对角线(左上角到右下角)上都是1, 首先,如果某行全是0或者某列全是0必然不满足情况输出-1,如果能转换的话,那么必然可以通过全由行(列)变换得到: 还有就是对角线上的N个 ...
- 大话https演化过程(对称加密、非对称加密、公钥、私钥、数字签名、数字证书)
大话https演化过程(包括概念:对称加密.非对称加密.公钥.私钥.数字签名.数字证书.https访问全过程) 在网络上发送数据是非常不安全的,非常容易被劫持或是被篡改,所以每次定向发送数据你都可 ...
- 找回 linux root密码的几种方法
第1种方法: 1.在系统进入单用户状态,直接用passwd root去更改 2.用安装光盘引导系统,进行linux rescue状态,将原来/分区挂接上来,作法如下: Java代码 #> c ...