链接:

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(没太懂)。

代码:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. const int MAXN = 1e5+10;
  5. const int MOD = 1e9+7;
  6. LL dp[MAXN];
  7. int a[MAXN];
  8. int n;
  9. int main()
  10. {
  11. int t;
  12. scanf("%d", &t);
  13. while(t--)
  14. {
  15. memset(dp, 0, sizeof(dp));
  16. scanf("%d", &n);
  17. a[0] = 0;
  18. bool flag = true;
  19. for (int i = 1;i <= n;i++)
  20. {
  21. scanf("%d", &a[i]);
  22. if (a[i] < a[i-1] || a[i] >= n || (i != 1 && a[i] == 0))
  23. flag = false;
  24. }
  25. if (a[1] != 0)
  26. flag = false;
  27. if (!flag)
  28. {
  29. puts("0");
  30. continue;
  31. }
  32. dp[1] = 1;
  33. for (int i = 2;i <= n;i++)
  34. {
  35. if (a[i] > a[i-1])
  36. dp[i] = (dp[i-1]*2)%MOD;
  37. else
  38. {
  39. LL sp = a[i]-i+2;
  40. dp[i] = (dp[i-1]*sp)%MOD;
  41. }
  42. }
  43. printf("%d\n", (int)(dp[n]%MOD));
  44. }
  45. return 0;
  46. }

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. linux服务器搭建lnmp php 微擎环境备用

    以前的时候装个php环境各种的配置麻烦啊,于是乎我就像搜搜一键安装php环境,果然 lamp 和phpstudy 两个环境软件都支持,最后发现lamp 还合胃口就选择了lamp https://lnm ...

  2. Django框架2——模板

    django框架2--模板 直接将HTML硬编码到你的视图里却并不是一个好主意: 对页面设计进行的任何改变都必须对 Python 代码进行相应的修改. 站点设计的修改往往比底层 Python 代码的修 ...

  3. sublime3 安装markdown插件

    sublime3 安装markdown插件 第一步安装package control 自动安装package control 手动安装package control 安装具体的markdown相关的p ...

  4. PAT(B) 1028 人口普查(C)字符串

    题目链接:1028 人口普查 (20 point(s)) 题目描述 某城镇进行人口普查,得到了全体居民的生日.现请你写个程序,找出镇上最年长和最年轻的人. 这里确保每个输入的日期都是合法的,但不一定是 ...

  5. WUSTOJ 1333: Sequential game(Java)

    题目链接:1333: Sequential game Description Sequential detector is a very important device in Hardware ex ...

  6. PB笔记之数据窗口行不能编辑的原因

    这里不打勾就不能编辑行

  7. Hibernate配置流程

    操作数据库必须要设置数据库的连接属性: driver_class,url,username,password(hibernate.cfg.xml)     2. 编写对象跟表之间的映射关系(类名.hb ...

  8. 交流绕组 & 感应电机

    交流绕组 1. 为什么整距线圈产生的电动势最大? 整距时, 一个线圈的两根有效导体边之间相差180电角度, 线圈的节距因数为1, 线圈产生的电动势为单根导体边产生电动势的2倍, 为最大 2. 三相交流 ...

  9. Angular Material (Components Cdk) 学习笔记 Table

    refer : https://material.angular.io/cdk/table/overview https://material.angular.io/components/table/ ...

  10. Linux 查询端口被占用命令

    1.lsof -i:端口号 用于查看某一端口的占用情况,比如查看8000端口使用情况,lsof -i:8000 lsof -i:8080:查看8080端口占用 lsof abc.txt:显示开启文件a ...