UVALive 6177 The King's Ups and Downs
The King's Ups and Downs
This problem will be judged on UVALive. Original ID: 6177
64-bit integer IO format: %lld Java class name: Main
The king has guards of all different heights. Rather than line them up in increasing or decreasing height order, he wants to line them up so each guard is either shorter than the guards next to him or taller than the guards next to him (so the heights go up and down along the line). For example, seven guards of heights 160, 162, 164, 166, 168, 170 and 172 cm. could be arranged as:
or perhaps:
The king wants to know how many guards he needs so he can have a different up and down order at each changing of the guard for rest of his reign. To be able to do this, he needs to know for a given number of guards, n, how many different up and down orders there are:
For example, if there are four guards: 1, 2, 3, 4 can be arranged as:
For this problem, you will write a program that takes as input a positive integer n, the number of guards and returns the number of up and down orders for n guards of differing heights.
Source
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = ;
LL dp[maxn][],c[maxn][maxn];
void init(){
for(int i = ; i <= ; ++i){
c[i][] = c[i][i] = ;
for(int j = ; j < i; ++j)
c[i][j] = c[i-][j-] + c[i-][j];
}
dp[][] = dp[][] = dp[][] = dp[][] = ;
for(int i = ; i <= ; ++i){
LL tmp = ;
for(int j = ; j < i; ++j)
tmp += dp[j][]*dp[i - j - ][]*c[i-][j];
dp[i][] = dp[i][] = (tmp>>);
}
}
int main(){
init();
int kase,cs,n;
scanf("%d",&kase);
while(kase--){
scanf("%d%d",&cs,&n);
printf("%d %lld\n",cs,n == ?:dp[n][]<<);
}
return ;
}
UVALive 6177 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 4489 The King’s Ups and Downs
http://acm.hdu.edu.cn/showproblem.php?pid=4489 题意:有n个身高不同的人,计算高低或低高交错排列的方法数. 思路:可以按照身高顺序依次插进去. d[i][ ...
- The King’s Ups and Downs
有n个高矮不同的士兵,现在要将他们按高,矮依次排列,问有多少种情况. 化简为 n个人,求出可以形成波浪形状的方法数 #include <iostream> #include <cma ...
- 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日 动态规划一 ...
随机推荐
- Android 线程 Looper.prepare()、Looper.loop() 使用
优化项目过程中发现了一个非常Low的问题,整理一下.备忘: 说问题之前先看下HandlerThread的定义 一个封装了looper的线程: Looper用于封装了android线程中的消息循环. ...
- Linux系统编程——特殊进程之僵尸进程
僵尸进程(Zombie Process) 进程已执行结束,但进程的占用的资源未被回收.这种进程称为僵尸进程. 在每一个进程退出的时候,内核释放该进程全部的资源.包含打开的文件.占用的内存等. 可是仍然 ...
- luogu2770 航空路线问题 网络流
题目大意: 给定一张航空图,图中顶点代表城市,边代表 2 城市间的直通航线.现要求找出一条满足下述限制条件的且途经城市最多的旅行路线.(1)从最西端城市出发,单向从西向东途经若干城市到达最东端城市,然 ...
- C#操作INI文件(明天陪你看海)
C#操作INI文件 在很多的程序中,我们都会看到有以.ini为后缀名的文件,这个文件可以很方便的对程序配置的一些信息进行设置和读取,比如说我们在做一个程序后台登陆的时候,需要自动登录或者是远程配置数据 ...
- hdu 6112 今夕何夕(模拟)
今夕何夕 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- 洛谷 P3128 [ USACO15DEC ] 最大流Max Flow —— 树上差分
题目:https://www.luogu.org/problemnew/show/P3128 倍增求 lca 也写错了活该第一次惨WA. 代码如下: #include<iostream> ...
- 第7章 Android中访问网络资源
http://developer.android.com/index.html->https://developer.android.com/index.html https://develop ...
- XML案例(使用DOM4J解析XML文档)
1.Demo1.java package cn.itcast.dom4j; import java.io.File;import java.io.FileOutputStream;import jav ...
- xx网络--工具集合
-- D:\workspace\bajie_projram\BJ.srfcb\BJ.srfcb\BJ.srfcb 8jielicai_New\App_Code\common\pg.cs---GetHt ...
- Combotree--别样的构建层级json字符串
1.先看效果 2.需要使用层级json格式,如: 3.先不要着急怎么去实现它,先来想想怎么用对象来描述它 4.代码 protected void Page_Load(object sender, Ev ...