题目戳这里

最长下降子序列单调队列求法。

\(f_{i,j,k}\)表示考虑前\(i\)个数,\(g_1 = j,g_2 = k\)的方案数。转移:

$$f_{i,j,k} = \sum_{p = k+1}{j}f_{i-1,p,k}+\sum_{p=0}kf_{i-1,j,p}$$

二维前缀和优化。复杂度\(O(NK^2)\)。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
using namespace std; const int maxk = 201;
int f[2][maxk][maxk],N,K,rhl,ans; int main()
{
freopen("1696.in","r",stdin);
freopen("1696.out","w",stdout);
scanf("%d %d %d",&N,&K,&rhl);
for (int i = 1;i <= K;++i) f[1][i][0] = 1;
for (int p = 2,now = 0,last = 1,inc;p <= N;++p,swap(now,last))
{
for (int i = 1;i <= K;++i)
{
for (int j = i-1;j >= 0;--j)
{
f[last][i][j] += f[last][i][j+1];
if (f[last][i][j] >= rhl) f[last][i][j] -= rhl;
}
for (int j = 0;j < i;++j)
{
f[last][i][j] += f[last][i-1][j];
if (f[last][i][j] >= rhl) f[last][i][j] -= rhl;
}
}
memset(f[now],0,sizeof f[now]);
for (int i = 1;i <= K;++i)
for (int j = 0;j < i;++j)
{
f[now][i][j] = f[last][i][j]-f[last][j][j]-f[last][i][j+1]+f[last][j][j+1];
while (f[now][i][j] >= rhl) f[now][i][j] -= rhl;
while (f[now][i][j] < 0) f[now][i][j] += rhl;
if (j)
{
inc = f[last][i][0]-f[last][i-1][0]-f[last][i][j+1]+f[last][i-1][j+1];
while (inc >= rhl) inc -= rhl; while (inc < 0) inc += rhl;
f[now][i][j] += inc; if (f[now][i][j] >= rhl) f[now][i][j] -= rhl;
}
}
}
for (int i = 1;i <= K;++i)
for (int j = 0;j < i;++j)
{
ans += f[N&1][i][j];
if (ans >= rhl) ans -= rhl;
}
printf("%d\n",ans+1);
fclose(stdin); fclose(stdout);
return 0;
}

URAL1696 Salary for Robots的更多相关文章

  1. 每日英语:Robots To Revolutionize China

    A new worker's revolution is rising in China and it doesn't involve humans. With soaring wages and a ...

  2. [LeetCode] Department Highest Salary 系里最高薪水

    The Employee table holds all employees. Every employee has an Id, a salary, and there is also a colu ...

  3. [LeetCode] Nth Highest Salary 第N高薪水

    Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...

  4. [LeetCode] Second Highest Salary 第二高薪水

    Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | S ...

  5. 网站 robots.txt 文件编写

    网站 robots.txt 文件编写 Intro robots.txt 是网站根目录下的一个纯文本文件,在这个文件中网站管理者可以声明该网站中不想被robots访问的部分,或者指定搜索引擎只收录指定的 ...

  6. Robots.txt - 禁止爬虫(转)

    Robots.txt - 禁止爬虫 robots.txt用于禁止网络爬虫访问网站指定目录.robots.txt的格式采用面向行的语法:空行.注释行(以#打头).规则行.规则行的格式为:Field: v ...

  7. (转载)robots.txt写法大全和robots.txt语法的作用

    1如果允许所有搜索引擎访问网站的所有部分的话 我们可以建立一个空白的文本文档,命名为robots.txt放在网站的根目录下即可.robots.txt写法如下:User-agent: *Disallow ...

  8. 2016 ccpc 网络选拔赛 F. Robots

    Robots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  9. robots.txt文件没错,为何总提示封禁

    大家好,我的robots.txt文件没错,为何百度总提示封禁,哪位高人帮我看看原因,在此谢过. 我的站点www.haokda.com,robots.txt如下: ## robots.txt for P ...

随机推荐

  1. Laravel -- 模型

    模型文件 <?php namespace App; use Illuminate\Database\Eloquent\Model; class Student extends Model { / ...

  2. ELK 安装部署实战 (最新6.4.0版本)

    一.实战背景 根据公司平台的发展速度,对于ELK日志分析日益迫切.主要的需求有: 1.用户行为分析 2.运营活动点击率分析 作为上述2点需求,安装最新版本6.4.0是非常有必要的,大家可根据本人之前博 ...

  3. Mysql通过Adjacency List(邻接表)存储树形结构

    转载自:https://www.jb51.net/article/130222.htm 以下内容给大家介绍了MYSQL通过Adjacency List (邻接表)来存储树形结构的过程介绍和解决办法,并 ...

  4. 生产Web架构优化方案(动态转静态)

    Infi-chu: http://www.cnblogs.com/Infi-chu/ 一.门户新闻业务: 1. 特点:网页一旦发布,再次改动网页内容的几率很低,新闻业务内容的静态化相对比较简单 2. ...

  5. HTML5 + JS 调取摄像头拍照下载

    <video id="video" width="640" height="480" autoplay></video&g ...

  6. Android面试收集录 网络与加密

    1.创建Socket对象需要至少指定哪些信息? IP(或域名)和端口号 Socket socket=new Socket("www.baidu.com",80); 2.如何使用So ...

  7. java Spring boot使用spring反射

    spring 反射 当你配置各种各样的bean时,是以配置文件的形式配置的,你需要用到哪些bean就配哪些,spring容器就会根据你的需求去动态加载,你的程序就能健壮地运行. 1.可以通过类名去实例 ...

  8. Linux安装防火墙

    1.安装防火墙 1)yum install iptables(centos) 安装IPtables服务 yum install iptables-services 2)清楚规则iptables -F ...

  9. windows系统下npm升级的正确姿势以及原理

    本文来自网易云社区 作者:陈观喜 网上关于npm升级很多方法多种多样,但是在windows系统下不是每种方法都会正确升级.其中在windows系统下主要的升级方法有以下三种: 首先最暴力的方法删掉no ...

  10. Java的HashMap和HashTable

    Java的HashMap和HashTable 1. HashMap 1)  hashmap的数据结构 Hashmap是一个数组和链表的结合体(在数据结构称“链表散列“),如下图示: 当我们往hashm ...