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 ...
随机推荐
- FZU2018级算法第五次作业 missile(排序+枚举)
在解题报告之前,首先对同一次作业中另外一题(求逆序对)某人在未经冰少允许情况下,擅自登录冰少账号,原模原样剽窃冰少代码,并且最终还被评为优秀作业的行为表示严正抗议! 题目大意: 二维平面上给出 n 个 ...
- Linux基础-04-权限
1. 查看文件的权限 1) 使用ls –l命令查看文件上所设定的权限. -rw-r--r-- 1 root root 605 Mar 18 20:28 .jp1.tar.gz 权限信息 属主 属组 文 ...
- WUSTOJ 1315: 杜学霸和谭女神(Java)
题目链接:
- JAVA基础学习_命名规范和注释
一.命名规范 1. 项目名全部小写 2. 包名统一使用小写,点分隔符之间有且仅有一个自然语义的英语单词,包名统一使用单数形式.如果类名有复数含义,类名可以使用复数形式. 实际应用中: 各层命名规约: ...
- 基于thymeleaf实现简单登录
1.引入thymeleaf.静态资源等依赖 <dependency> <groupId>org.springframework.boot</groupId> < ...
- php json_encode() 中文保留
这几天遇到了一个问题 给java传json的时候 没有处理中文 那边拿数据的时候说不是中文的 需要转一下 方法: 实际应用中,当有中文字符时,当直接使用json_encode() 函数会使汉字不 ...
- iOS - 如何适配iOS10(插曲)
升级了系统10.12beta xcode8 出现一大推问题 ,连上架APP都成了问题.只能先解决这些问题,再研究3D引擎了. 2016年9月7日,苹果发布iOS 10.2016年9月14日,全新的操 ...
- python的excel处理之openpyxl
一.颜色处理 cell = sheet.cell(row, col)font = Font(size=12, bold=False, name='Arial', color=colors.BLACK) ...
- Python 使用gevent下载图片案例
import urllib.request import gevent from gevent import monkey monkey.patch_all() def downloader(img_ ...
- visualSVN server 安装成功,但是无法连接,url打不开
转自:https://www.oschina.net/question/878142_91825 点击开始–>程序->VisualSVN–>VisuaSVN Server Manag ...