[HZNUOJ1524]排队买票(DP)
题目链接:http://acm.hznu.edu.cn/JudgeOnline/problem.php?id=1524
简单分析后可以知道每一个手持两元的小朋友前面,售票员手里至少有一个一元。
假设dp(i, j)表示当有i个1元和j个2元的时候的排队方法(不重复),那么有:
dp(i, j)=∑k[0, j]dp(i-1, k), (i >= j)
题干讲n个人和k个人内部不同位置也算新的排列方法。那么最后要乘上A(k,k)*A(n,n)
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; const int maxn = ;
int n, m, k;
int dp[maxn][maxn]; int main() {
// freopen("in", "r", stdin);
scanf("%d %d %d", &m, &n, &k);
memset(dp, , sizeof(dp));
int ak = , an = ;
for(int i = ; i <= k; i++) ak *= i;
for(int i = ; i <= n; i++) an *= i;
dp[][] = ;
dp[][] = ;
for(int i = ; i <= n; i++) {
for(int j = ; j <= i; j++) {
for(int k = ; k <= j; k++) {
dp[i][j] += dp[i-][k];
}
}
}
printf("%d\n", dp[n][k]*ak*an);
return ;
}
[HZNUOJ1524]排队买票(DP)的更多相关文章
- JDOJ 1928: 排队买票
JDOJ 1928: 排队买票 JDOJ传送门 Description 一场演唱会即将举行.现有n个歌迷排队买票,一个人买一张,而售票处规定,一个人每次最多只能买两张票.假设第i位歌迷买一张票需要时间 ...
- 杭电1133 排队买票 catalan
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- 安科 OJ 1054 排队买票 (递归,排列组合)
时间限制:1 s 空间限制:128 M 题目描述 有M个小孩到公园玩,门票是1元.其中N个小孩带的钱为1元,K个小孩带的钱为2元.售票员没有零钱,问这些小孩共有多少种排队方法,使得售票员总能找得开零钱 ...
- dp(买票优惠)
CodeForces - 1154F There are n shovels in the nearby shop. The i-th shovel costs ai bourles. Misha h ...
- FZU 2029 买票问题 树状数组+STL
题目链接:买票问题 思路:优先队列维护忍耐度最低的人在队首,leave操作ok. vis数组记录从1到n的编号的人们是不是在队列中,top维护队首的人的编号.pop操作搞定. 然后,check操作就是 ...
- java多线程编程(3)买票
1,买票非同步版本 http://www.cnblogs.com/anbylau2130/archive/2013/04/17/3025347.html很详细 public class 多线程2 { ...
- 你好,C++(37)上车的人请买票!6.3.3 用虚函数实现多态
6.3.3 用虚函数实现多态 在理解了面向对象的继承机制之后,我们知道了在大多数情况下派生类是基类的“一种”,就像“学生”是“人”类中的一种一样.既然“学生”是“人”的一种,那么在使用“人”这个概念 ...
- Java 数量为5的线程池同时运行5个窗口买票,每隔一秒钟卖一张票
/** * 1.创建线程数量为5的线程池 * 2.同时运行5个买票窗口 * 3.总票数为100,每隔一秒钟卖一张票 * @author Administrator * */ public class ...
- poj 2828 Buy Tickets 【买票插队找位置 输出最后的位置序列+线段树】
题目地址:http://poj.org/problem?id=2828 Sample Input 4 0 77 1 51 1 33 2 69 4 0 20523 1 19243 1 3890 0 31 ...
随机推荐
- 【BZOJ】【3007】拯救小云公主
思路题 我的naive的做法是二分答案+判定是否有路径可走……但是没有正确理解[走的方向任意]这句话…… 其实就是说想咋走咋走= =360°无死角乱走…… 所以其实是个平面上的问题…… 我们可以换个方 ...
- Basic knowledge of javaScript (keep for myself)
1. 函数表达式 JavaScript 函数可以通过一个表达式定义.eg. var x = function (a, b) {return a * b}; so: var x = function ( ...
- Binary Indexed Tree 2D 分类: ACM TYPE 2014-09-01 08:40 95人阅读 评论(0) 收藏
#include <cstdio> #include <cstdlib> #include <climits> #include <cstring> # ...
- 驱动笔记 - file_operations
#include <linux/fs.h> struct file_operations { struct module *owner; loff_t (*llseek) (struct ...
- 定时器 corn 表达式
一个cron表达式有至少6个(也可能7个)有空格分隔的时间元素.按顺序依次为1.秒(0~59)2.分钟(0~59)3.小时(0~23)4.天(月)(0~31,但是你需要考虑你月的天数)5.月(0~11 ...
- Sqli-labs less 48
Less-48 本关与less-46的区别在于报错注入不能使用,不进行错误回显,因此其他的方法我们依旧是可以使用的. 可以利用sort=rand(true/false)进行判断. http://127 ...
- Javascript与Flash通信全解析
原文:https://www.imququ.com/post/39.html Flash已经提供了ExternalInterface接口与JavaScript通信,ExternalInterface有 ...
- To Use Ubuntuubunt
1.rename PC; modify the /etc/hostname. 2.Use root account; 1.set the password for root account: sudo ...
- android开发环境搭建(for 驱动开发人员)
前言 一.android驱动的开发流程 1: 写LINUX驱动 2: 写LINUX应用测试程序 3: 写JNI接口,用来包装第二步写的应用 (要用NDK来编译) 生成一个.SO文件,相当于CE下的DL ...
- eclipse工程设置的问题