BZOJ 4321 queue2
4321: queue2
Description
Input
Output
Sample Input
Sample Output
样例解释:有两种方案 2 4 1 3 和 3 1 4 2
/**************************************************************
Problem: 4321
User: Doggu
Language: C++
Result: Accepted
Time:484 ms
Memory:852 kb
****************************************************************/ #include <cstdio>
long long n, f[][][], cur, MOD=;
inline void add(long long &a,long long b) {if(b>MOD) b%=MOD;a=a+b>MOD?a+b-MOD:a+b;}
int main() {
scanf("%d",&n);
f[cur][][]=;
for( int i = ; i <= n; i++ ) {
cur^=;
for( int j = ; j <= i-; j++ ) {
f[cur][j][]=f[cur^][j][];
if(j) add(f[cur][j][],f[cur^][j-][]);
if(j) add(f[cur][j][],f[cur^][j-][]*);
f[cur][j][]=f[cur^][j+][]*j;
add(f[cur][j][],f[cur^][j+][]*(j+));
add(f[cur][j][],f[cur^][j][]*(i-j-));
add(f[cur][j][],f[cur^][j][]*(i-j-));
}
}
printf("%d\n",f[cur][][]);
return ;
}
DP
BZOJ 4321 queue2的更多相关文章
- BZOJ 4321: queue2( dp )
dp(i, j, 1)表示前i个, 有j对是不合法的, i和i-1是在一起的. dp(i, j, 0)表示前i个, 有j对是不合法的, i和i-1不在一起的. 转移我们只需考虑是多了一对不合法的还是少 ...
- BZOJ 4321 DP
思路: 这个DP太神了- 完全没想到 http://blog.csdn.net/geotcbrl/article/details/49663401 //By SiriusRen #include &l ...
- dp专练
dp练习. codevs 1048 石子归并 区间dp #include<cstdio> #include<algorithm> #include<cstring> ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 两种dp模型
两个常见模型 bzoj 4321 题意:编号为1~n的人排成一排,问有多少种排法使得任意相邻两人的编号之差不为1或-1. n<=1000 排列计数问题:考虑把数从小到大插入的过程进行dp. 设 ...
- dp培训完结(8.9)
概率与期望dp 期望: 为什么下面的式子成立? 若x可以取1,2,3,则x+c可以取1+c,2+c,3+c..........x*c可以取1*c,2*c,3*c why? 举个例子(E(x+y)=E( ...
- BZOJ 2127: happiness [最小割]
2127: happiness Time Limit: 51 Sec Memory Limit: 259 MBSubmit: 1815 Solved: 878[Submit][Status][Di ...
- BZOJ 3275: Number
3275: Number Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 874 Solved: 371[Submit][Status][Discus ...
- BZOJ 2879: [Noi2012]美食节
2879: [Noi2012]美食节 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 1834 Solved: 969[Submit][Status] ...
随机推荐
- 3分钟手把手带你搭建基于selenium的自动化框架
1 .什么是seleniumSelenium 是一个基于浏览器的自动化工具,它提供了一种跨平台.跨浏览器的端到端的web自动化解决方案.Selenium主要包括三部分:Selenium IDE.Sel ...
- 基本数据结构 -- 栈简介(C语言实现)
栈是一种后进先出的线性表,是最基本的一种数据结构,在许多地方都有应用. 一.什么是栈 栈是限制插入和删除只能在一个位置上进行的线性表.其中,允许插入和删除的一端位于表的末端,叫做栈顶(top),不允许 ...
- idea打断点是灰色的
点击这个图标,debug的断点就是灰色的,debug功能被禁用
- mybatis批量插入oracle
<insert id="batchInsert" parameterType="java.util.List"> INSERT INTO TEST( ...
- so easy, too happy
一.预估与实际 PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟) Planning 计划 • Estimate • 估计这个任务需要多 ...
- maven 阿里仓库配置文件
<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Soft ...
- 【贪心算法】POJ-1017
一.题目 Description A factory produces products packed in square packets of the same height h and of th ...
- 简单实现wc.exe软件基本功能
简单实现wc.exe软件基本功能 软件需求分析: 一.基本功能 支持 -c 统计字符数(char count) 支持 -w 统计单词数(word count) 支持 -l 统计总行数(line ...
- AWS EC2安装docker时的问题
在AWS EC2的实例(Ubuntu)里面安装docker时,使用通常的安装步骤 :~$ sudo apt-get update :~$ sudo apt-get install docker 安装完 ...
- 使用GatewayWorker 开发个即时聊天demo
前言: 上手册以示尊重:https://www.kancloud.cn/walkor/gateway-worker/326138: https://www.cnblogs.com/fuqiang88/ ...