The 2019 China Collegiate Programming Contest Harbin Site I. Interesting Permutation
链接:
https://codeforces.com/gym/102394/problem/I
题意:
DreamGrid has an interesting permutation of 1,2,…,n denoted by a1,a2,…,an. He generates three sequences f, g and h, all of length n, according to the permutation a in the way described below:
For each 1≤i≤n, fi=max{a1,a2,…,ai};
For each 1≤i≤n, gi=min{a1,a2,…,ai};
For each 1≤i≤n, hi=fi−gi.
BaoBao has just found the sequence h DreamGrid generates and decides to restore the original permutation. Given the sequence h, please help BaoBao calculate the number of different permutations that can generate the sequence h. As the answer may be quite large, print the answer modulo 109+7.
思路:
考虑,某个位置为n或者h[i] > h[i+1] ,和第一个位置不为0时,答案都为0.
其他情况,h[i] == h[i+1],考虑前面的空位数, h[i] < h[i+1],可以插最小值,也可以插最大值, 直接×2(没太懂)。
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 1e5+10;
const int MOD = 1e9+7;
LL dp[MAXN];
int a[MAXN];
int n;
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
memset(dp, 0, sizeof(dp));
scanf("%d", &n);
a[0] = 0;
bool flag = true;
for (int i = 1;i <= n;i++)
{
scanf("%d", &a[i]);
if (a[i] < a[i-1] || a[i] >= n || (i != 1 && a[i] == 0))
flag = false;
}
if (a[1] != 0)
flag = false;
if (!flag)
{
puts("0");
continue;
}
dp[1] = 1;
for (int i = 2;i <= n;i++)
{
if (a[i] > a[i-1])
dp[i] = (dp[i-1]*2)%MOD;
else
{
LL sp = a[i]-i+2;
dp[i] = (dp[i-1]*sp)%MOD;
}
}
printf("%d\n", (int)(dp[n]%MOD));
}
return 0;
}
The 2019 China Collegiate Programming Contest Harbin Site I. Interesting Permutation的更多相关文章
- The 2019 China Collegiate Programming Contest Harbin Site
题解: https://files.cnblogs.com/files/clrs97/HarbinEditorialV2.zip Code: A. Artful Paintings /* let x= ...
- The 2019 China Collegiate Programming Contest Harbin Site F. Fixing Banners
链接: https://codeforces.com/gym/102394/problem/F 题意: Harbin, whose name was originally a Manchu word ...
- The 2019 China Collegiate Programming Contest Harbin Site K. Keeping Rabbits
链接: https://codeforces.com/gym/102394/problem/K 题意: DreamGrid is the keeper of n rabbits. Initially, ...
- The 2019 China Collegiate Programming Contest Harbin Site J. Justifying the Conjecture
链接: https://codeforces.com/gym/102394/problem/J 题意: The great mathematician DreamGrid proposes a con ...
- 模拟赛小结:The 2019 China Collegiate Programming Contest Harbin Site
比赛链接:传送门 上半场5题,下半场疯狂挂机,然后又是差一题金,万年银首也太难受了. (每次银首都会想起前队友的灵魂拷问:你们队练习的时候进金区的次数多不多啊?) Problem J. Justify ...
- The 2017 China Collegiate Programming Contest, Hangzhou Site Solution
A: Super_palindrome 题面:给出一个字符串,求改变最少的字符个数使得这个串所有长度为奇数的子串都是回文串 思路:显然,这个字符串肯定要改成所有奇数位相同并且所有偶数位相同 那统计一下 ...
- 2019 China Collegiate Programming Contest Qinhuangdao Onsite
传送门 D - Decimal 题意: 询问\(\frac{1}{n}\)是否为有限小数. 思路: 拆质因子,看是不是只包含2和5即可,否则除不尽. Code #include <bits/st ...
- 2019 China Collegiate Programming Contest Qinhuangdao Onsite F. Forest Program(DFS计算图中所有环的长度)
题目链接:https://codeforces.com/gym/102361/problem/F 题意 有 \(n\) 个点和 \(m\) 条边,每条边属于 \(0\) 或 \(1\) 个环,问去掉一 ...
- The 2015 China Collegiate Programming Contest A. Secrete Master Plan hdu5540
Secrete Master Plan Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Othe ...
随机推荐
- Tp5.1 管理后台开发纪要
1. tp5.1 对网页是有缓存机制的 E:\phpStudy\PHPTutorial\WWW\NewAdmin\thinkphp\library\think\Template.php 下displa ...
- python爬虫-爬取你想要的小姐姐
一.准备 1. 原地址 2. 检查html发现,网页是有规则的分页, 最大图片的class为pic-large 二.代码 import requests import os from bs4 impo ...
- Mybatis笔记2
使用Mybatis完成的CRUD操作 个人总结的一些小规律 学习过程中碰到的错误: org.apache.ibatis.exceptions.PersistenceException: ### Err ...
- Python25之字典1
一.字典的意义 字典不同于前述的序列类型,他是一种映射类型,它的引入就是为了简化定义索引值和元素值存在的特定关系的定义和访问问题 二,字典定义 字典变量名 = {key1 : value1, key2 ...
- ORA-01618 ORA-19809: limit exceeded for recovery files
由于DB_RECOVERY_FILE_DEST_SIZE 参数设置太小,导致redo只能创建一组,无法创建节点二的日志组,节点二数据库无法启动,如下图: 修改参数后,节点二无法启动到mount模式,无 ...
- zabbix添加自定义监控(自动发现)遇到的问题
问题:zabbix添加自动发现端口,提示Value should be a JSON object [root@localhost zabbix_agentd.d]# zabbix_get -s 19 ...
- 使用dockers安装MySQL
事前准备 关闭selinux setenforce 0 vim /etc/sysconfig/selinux SELINUX=disabled # 若不关闭,使用docker启动mysql5.7镜像容 ...
- docker registry-v2 搭建私有仓库
参考官方文档:https://docs.docker.com/registry/deploying/ 参考 :http://www.tuicool.com/articles/6jEJZj 本例子使用两 ...
- copy 合并
copy /b xxx.jpg + yyy.txt zzz.jpg /b 二进制 /a 文本
- 在浏览器输入URL回车后发生了什么?
本文由 简悦 SimpRead 转码, 原文地址 https://4ark.me/post/b6c7c0a2.html 这个问题已经是老生常谈了,更是经常被作为面试的压轴题出现,网上也有很多文章,但最 ...