链接:

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的更多相关文章

  1. The 2019 China Collegiate Programming Contest Harbin Site

    题解: https://files.cnblogs.com/files/clrs97/HarbinEditorialV2.zip Code: A. Artful Paintings /* let x= ...

  2. 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 ...

  3. 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, ...

  4. 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 ...

  5. 模拟赛小结:The 2019 China Collegiate Programming Contest Harbin Site

    比赛链接:传送门 上半场5题,下半场疯狂挂机,然后又是差一题金,万年银首也太难受了. (每次银首都会想起前队友的灵魂拷问:你们队练习的时候进金区的次数多不多啊?) Problem J. Justify ...

  6. The 2017 China Collegiate Programming Contest, Hangzhou Site Solution

    A: Super_palindrome 题面:给出一个字符串,求改变最少的字符个数使得这个串所有长度为奇数的子串都是回文串 思路:显然,这个字符串肯定要改成所有奇数位相同并且所有偶数位相同 那统计一下 ...

  7. 2019 China Collegiate Programming Contest Qinhuangdao Onsite

    传送门 D - Decimal 题意: 询问\(\frac{1}{n}\)是否为有限小数. 思路: 拆质因子,看是不是只包含2和5即可,否则除不尽. Code #include <bits/st ...

  8. 2019 China Collegiate Programming Contest Qinhuangdao Onsite F. Forest Program(DFS计算图中所有环的长度)

    题目链接:https://codeforces.com/gym/102361/problem/F 题意 有 \(n\) 个点和 \(m\) 条边,每条边属于 \(0\) 或 \(1\) 个环,问去掉一 ...

  9. 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 ...

随机推荐

  1. netty 实现心跳检查--断开重连--通俗易懂

    一.心跳介绍 网络中的接收和发送数据都是使用操作系统中的SOCKET进行实现.但是如果此套接字已经断开,那发送数据和接收数据的时候就一定会有问题. 1.心跳机制: 是服务端和客户端定时的发送一个心跳包 ...

  2. python爬虫-豆瓣电影的尝试

    一.背景介绍 1. 使用工具 Pycharm 2. 安装的第三方库 requests.BeautifulSoup 2.1 如何安装第三方库 File => Settings => Proj ...

  3. 1.关于Python,你可能不知道的

    启示录 写在前面———— 至于python有多牛逼,这里不介绍了,安装也不说了,网上一堆一堆的安装教程. 本文只介绍需要知道的 常识知识———— 1.python 发音:英 [ˈpaɪθən] 美 [ ...

  4. Python--递归函数实现:多维嵌套字典数据无限遍历

    原创:多层嵌套字典无限遍历,实现当value值以特殊字符$开头,并且等于某项值时,用随机函数替换该参数 """处理前的字典{'patient': {'avatarPic' ...

  5. C++进行字母大小写转换

    #include <iostream> #include <Windows.h> #include <string> using namespace std; in ...

  6. MySQL DBA的KPI考核指标有哪些

    绩效考核是对一名员工所作工作的数量.质量.难度.强度.效率的量化考量.由于DBA的工作性质与纯粹的研发人员或运维人员有所区别,对DBA的KPI考核指标也有其特殊性.参考以往的经验和一些较大的DBA t ...

  7. idea的项目结构

    idea项目结构: 一般是创建一个empty project,然后再创建一个个的Module.

  8. Java Embeded 包 与各个架构之间的关系

    Oracle Java Embedded Suite 7.0 for Linux x86        V37917-01.zip        Oracle Java Embedded Suite ...

  9. ubuntu修改密码

    ubuntu修改密码 本文链接:https://blog.csdn.net/heybob/article/details/9095727 修改root密码: 1,$sudo su,输入密码进入root ...

  10. Visual Studio 2013/15/17小技巧

    1.Ctrl + F10 可以直接运行到光标处,而不用F10 逐过程 F11 逐语句了 2.当有多个断点时,按F5可以切换到下一个断点. 3.Ctrl+Shift+空格 显示函数签名,上下键可以查看所 ...