URAL1696 Salary for Robots
题目戳这里。
最长下降子序列单调队列求法。
\(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的更多相关文章
- 每日英语:Robots To Revolutionize China
A new worker's revolution is rising in China and it doesn't involve humans. With soaring wages and a ...
- [LeetCode] Department Highest Salary 系里最高薪水
The Employee table holds all employees. Every employee has an Id, a salary, and there is also a colu ...
- [LeetCode] Nth Highest Salary 第N高薪水
Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...
- [LeetCode] Second Highest Salary 第二高薪水
Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | S ...
- 网站 robots.txt 文件编写
网站 robots.txt 文件编写 Intro robots.txt 是网站根目录下的一个纯文本文件,在这个文件中网站管理者可以声明该网站中不想被robots访问的部分,或者指定搜索引擎只收录指定的 ...
- Robots.txt - 禁止爬虫(转)
Robots.txt - 禁止爬虫 robots.txt用于禁止网络爬虫访问网站指定目录.robots.txt的格式采用面向行的语法:空行.注释行(以#打头).规则行.规则行的格式为:Field: v ...
- (转载)robots.txt写法大全和robots.txt语法的作用
1如果允许所有搜索引擎访问网站的所有部分的话 我们可以建立一个空白的文本文档,命名为robots.txt放在网站的根目录下即可.robots.txt写法如下:User-agent: *Disallow ...
- 2016 ccpc 网络选拔赛 F. Robots
Robots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- robots.txt文件没错,为何总提示封禁
大家好,我的robots.txt文件没错,为何百度总提示封禁,哪位高人帮我看看原因,在此谢过. 我的站点www.haokda.com,robots.txt如下: ## robots.txt for P ...
随机推荐
- Django模板语言(DTL)基础
## 模板变量 - 普通变量 {{ name }} - 对象变量(使用点号访问对象属性和方法,方法不加括号) {{ person.name }} ## 常用模板标签 # if标签,支持and,or,n ...
- typecho博客组插件:openSug.js百度搜索框下拉提示免费代码
Typecho候选搜索增强插件:安装openSug插件即可获得带有“搜索框提示”功能的搜索框,让Typecho搜索更便捷! 支持百度.谷歌.雅虎.Yandex.360好搜.UC神马.酷狗.优酷.淘 ...
- mysql5.7数据库与5.7之前版本比较
数据库初始化方式变更 <5.7 版本 mysql_install_db >5.7 版本 bin/mysqld --initialize --user =mysql --basedir=/u ...
- 中国农产品信息网站scrapy-redis分布式爬取数据
---恢复内容开始--- 基于scrapy_redis和mongodb的分布式爬虫 项目需求: 1:自动抓取每一个农产品的详细数据 2:对抓取的数据进行存储 第一步: 创建scrapy项目 创建爬虫文 ...
- ruby 类库组成
一. 核心类库: 二.标准类库: 文本 base64.rb 处理Base64编码的模块 csv.rb CSV(Comma Separated Values)库 ruby 1.8 特性 ...
- C语言实现斐波那契数列
1.函数一用递归实现 2.函数二用循环实现 #include<stdio.h> #include<stdlib.h> #pragma warning(disable:4996) ...
- System.Speech使用
使用微软语音库 使用微软语音库可以很快速的制作一个小应用,比如一个唐诗的朗诵工具.本示例也是使用微软语音库,制作了一个唐诗宋词朗诵的应用,仅供加深学习印象 首先是要引入System.Speech库 然 ...
- codeblocks编译出错问题的解答!(编译c++ 或者c程序)
典型错误:https://blog.csdn.net/jingmiaa/article/details/52054204 MinGW下载并配置gcc/g++编译环境:https://blog.csdn ...
- 为什么我要放弃javaScript数据结构与算法(第二章)—— 数组
第二章 数组 几乎所有的编程语言都原生支持数组类型,因为数组是最简单的内存数据结构.JavaScript里也有数组类型,虽然它的第一个版本并没有支持数组.本章将深入学习数组数据结构和它的能力. 为什么 ...
- ChemDraw Std 14性价比最高版本,即将下架
虽然ChemDraw Std 14是ChemOffice®14的基础组件,但是基础功能涵盖全面,是教育专供产品.根据官方最新消息ChemDraw系列软件产品线将进行全面的升级,ChemOffice®1 ...