题目戳这里

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

\(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. MIP缓存加速原理 MIP不仅仅只是CDN

    什么是MIP?我想我们现在都知道.可是你真的了解MIP吗?MIP加速原理是什么?MIP 是用 CDN 做加速的么?准确答案是:是,但不只是. 很多人并认为MIP百度排名会靠前,甚至权重会提高?作为一个 ...

  2. doT.js使用介绍

    doT.js特点是快,小,无依赖其他插件,压缩版仅有4K大小. doT.js详细使用介绍 使用方法: 1 2 3 4 5 6 7 {{ }} 模板   开始标记  结束标记 {{= }} 赋值 {{~ ...

  3. 初学tiny4412

    1.解压友善之臂提供的uboot make tiny4412_config make 然后将sd卡插到电脑上,编辑虚拟机,选择对应的usb口(usb3.0兼容),如果没有usb3.0,可能是虚拟机版本 ...

  4. SVM中的间隔最大化

    参考链接: 1.https://blog.csdn.net/TaiJi1985/article/details/75087742 2.李航<统计学习方法>7.1节 线性可分支持向量机与硬间 ...

  5. 网站标题被篡改成北京赛车、PK10的解决处理办法

    客户网站于近日被跳转到赌博网站,打开后直接跳转到什么北京赛车,PK10等内容的网站上去,客户网站本身做了百度的推广,导致所有访问用户都跳转到赌博网站上去,给客户带来很大的经济损失,再一个官方网站的形象 ...

  6. Java学习笔记十三:Java中的类和对象

    Java中的类和对象 一:什么是对象: 总的来说就是"万物皆对象",客观存在的事物皆为对象.是计算机所关注的具体信息. 对象(object)是一件事.一个物体.一个名词,或可以获得 ...

  7. 001---Linux系统的启动过程

    Linux系统的启动过程 按下电源 开机自检(BIOS):检查cpu.内存.硬盘是否有问题,找到启动盘. MBR引导(master boot record):主引导记录,读取存储设备的512bytes ...

  8. 在WPF中自定义控件(3) CustomControl (上)

    原文:在WPF中自定义控件(3) CustomControl (上) 在WPF中自定义控件(3) CustomControl (上)                              周银辉 ...

  9. mutation与vuex区别

    vuex- action   1.当点发送过快,页面中渲染的内容与state中的数据不一致,vuex里面的state变得慢,且不持续更新 2.action中是可以做到页面中state中数据保持一致 责 ...

  10. ajax设置自定义头

    一.setting参数 headers $.ajax({ headers: {        Accept: "application/json; charset=utf-8"  ...