真的没有什么会写的东西了QAQ

原题:

As one of the most powerful brushes, zhx is required to give his juniors n problems.
zhx thinks the ith problem's difficulty is i. He wants to arrange these problems in a beautiful way.
zhx defines a sequence {ai} beautiful if there is an i that matches two rules below:
1: a1..ai are monotone decreasing or monotone increasing.
2: ai..an are monotone decreasing or monotone increasing.
He wants you to tell him that how many permutations of problems are there if the sequence of the problems' difficulty is beautiful.
zhx knows that the answer may be very huge, and you only need to tell him the answer module p.

一句话题意:

求有多少种n排列单峰或单调答案膜p

1<=n,p<=1e18

n个数里选最最大放在第i个位置,选i-1个数放前面并递增,剩下的放后面并递减,这样有c(i-1,n)种

(注意不能简单地挑i个数放前面剩下的放后面,一定要先有一个最大/小的数在峰上

所有的i加起来就有Σ_{i=0}^{n-1}c(i,n)=2^(n-1)种

先递减再递增同理,所以方案数*2=2^n种

全部递增和全部递减多算了一遍,减2,最后答案是2^n-2

因为膜数很大所以快速幂的同时快速乘

代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<cmath>
 6 using namespace std;
 7 #define ll long long
 8 int rd(){int z=0,mk=1;  char ch=getchar();
 9     while(ch<'0'||ch>'9'){if(ch=='-')mk=-1;  ch=getchar();}
10     while(ch>='0'&&ch<='9'){z=(z<<3)+(z<<1)+ch-'0';  ch=getchar();}
11     return z*mk;
12 }
13 ll n,m;
14 ll mtp(ll x,ll y){
15     ll bs=x,z=0;
16     while(y){  if(y&1)  z=(z+bs)%m;  bs=(bs+bs)%m;  y>>=1;}
17     return z;
18 }
19 ll qcp(ll x,ll y){
20     ll bs=x,z=1;
21     while(y){  if(y&1)  z=mtp(bs,z);  bs=mtp(bs,bs);  y>>=1;}
22     return z;
23 }
24 int main(){freopen("ddd.in","r",stdin);
25     while(scanf("%I64d%I64d",&n,&m)!=EOF){
26         if(n==1){  printf("%I64d\n",n%m);  continue;}
27         printf("%I64d\n",(qcp(2,n)-2+m)%m);
28     }
29     return 0;
30 }

View Code

转载于:https://www.cnblogs.com/JSL2018/p/6908035.html

【HDU5187】contest相关推荐

  1. AtCoder Beginner Contest 297 【E-F】题解

    AtCoder Beginner Contest 297 [E-F]题解 E - Kth Takoyaki Set 多重指针,具体可参考leetcode简化版题目 丑数 import math imp ...

  2. 【*2000】【2018-2019 ICPC, NEERC, Southern Subregional Contest C 】Cloud Computing

    [链接] 我是链接,点我呀:) [题意] [题解] 我们可以很容易知道区间的每个位置有哪些安排可以用. 显然 我们优先用那些花费的钱比较少的租用cpu方案. 但一个方案可供租用的cpu有限. 我们可以 ...

  3. 【AtCoder Regular Contest 082】Derangement

    [链接]点击打开链接 [题意] 在这里写题意 [题解] 贪心. 连续一块的p[i]==i的话,对答案的贡献就应该为(这个连续块的长度+1)/2; 长度为1的也正确. (也即两两相邻的互换位置.) [错 ...

  4. 【USACO】2017 December Contest, Platinum题解

    [比赛经历] 大概顺利满分了,就是T2的代码比较难调. T2能够直观地反映出GDB和输出调试结合的优越性. [T1]Standing Out from the Herd [题目链接] 点击打开链接 [ ...

  5. 2018年东北农业大学春季校赛 D wyh的迷宫【搜索】

    链接:https://www.nowcoder.com/acm/contest/93/D 来源:牛客网 题目描述 给你一个n*m的迷宫,这个迷宫中有以下几个标识: s代表起点 t代表终点 x代表障碍物 ...

  6. kettle 日志存到mysql_kettle作业(job)调用转换,设置变量,写日志到数据库中【转】...

    构造函数,const char*与c_str /**************************************************************************** ...

  7. 【LeetCode】字符串 string(共112题)

    [3]Longest Substring Without Repeating Characters (2019年1月22日,复习) [5]Longest Palindromic Substring ( ...

  8. 2018年东北农业大学春季校赛 E 阶乘后的0【数论】

    链接:https://www.nowcoder.com/acm/contest/93/E 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言5242 ...

  9. 【HDOJ图论题集】【转】

    1 =============================以下是最小生成树+并查集====================================== 2 [HDU] 3 1213 How ...

最新文章

  1. 《java入门第一季》之面向对象面试题(继承中构造方法的关系)
  2. 【转】深入探讨 Android 传感器
  3. UA MATH564 概率论VI 数理统计基础3 卡方分布上
  4. PAT甲级1051 Pop Sequence:[C++题解]模拟栈、判断序列是否是合法的出栈序列
  5. mysql左键关联_MySQL的:左键删除重复列加入,3个表
  6. python时间序列数据分析,Python数据分析之时间序列
  7. 探索比特币源码7-哈希
  8. 在资源使用状况视图中查看资源的负荷情况
  9. ajax学习笔记之一
  10. python编程是啥-Python编程
  11. python 中定义的函数 如何在main中调用_在python中,在定义类时自动运行函数的方法?_class_酷徒编程知识库...
  12. axvspan函数--Matplotlib
  13. 小米12s 12sU 12sP 12x 12pro天玑版等小米机型通用解锁bl 刷写root全部步骤教程
  14. 配置嵌入式Servlet容器
  15. php货币2019年12月31日汇率,[外汇]2019年12月31日人民币汇率中间价新公告 今日美元兑人民币行情查询 - 南方财富网...
  16. 新买的显示器怎么测试软件,新买的电视如何检测屏幕?记住这个方法
  17. ps 导出矢量图为svg,并上传iconfont
  18. 科研绘图之R语言生存分析KM曲线累计风险表放在图片内部
  19. 【机器学习】训练集、验证集与测试集
  20. Java对Excel的读写详解(POI)

热门文章

  1. java 动态代理范例 InvocationHandler与Proxy
  2. hdu 1525 博弈
  3. DWR2学习笔记(一)
  4. java—IO流——读取键盘输入的字母并转换成大写字母输出在控制台上
  5. Mr.J--JS学习(事件处理函数包装)
  6. my footprint :走过的路
  7. 06 ansible剧本功能实践介绍
  8. 洛谷 P3320: bzoj 3991: LOJ 2182: [SDOI2015]寻宝游戏
  9. HDOJ_1004_Let the Balloon Rise
  10. Can't connect to MySQL server on 'ip' (13)