真的没有什么会写的东西了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

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

代码:

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
#define ll long long
int rd(){int z=,mk=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-')mk=-; ch=getchar();}
while(ch>=''&&ch<=''){z=(z<<)+(z<<)+ch-''; ch=getchar();}
return z*mk;
}
ll n,m;
ll mtp(ll x,ll y){
ll bs=x,z=;
while(y){ if(y&) z=(z+bs)%m; bs=(bs+bs)%m; y>>=;}
return z;
}
ll qcp(ll x,ll y){
ll bs=x,z=;
while(y){ if(y&) z=mtp(bs,z); bs=mtp(bs,bs); y>>=;}
return z;
}
int main(){freopen("ddd.in","r",stdin);
while(scanf("%I64d%I64d",&n,&m)!=EOF){
if(n==){ printf("%I64d\n",n%m); continue;}
printf("%I64d\n",(qcp(,n)-+m)%m);
}
return ;
}

【HDU5187】contest的更多相关文章

  1. 【HDU5187】zhx's contest

    [问题描述] 作为史上最强的刷子之一,zhx的老师让他给学弟(mei)们出n道题.zhx认为第i道题的难度就是i.他想要让这些题目排列起来很漂亮. zhx认为一个漂亮的序列{ai}下列两个条件均需满足 ...

  2. 【CF725D】Contest Balloons(贪心,堆)

    题意:acm队伍可以得气球,相同气球数是一个排名.每个队伍有一个气球数上限,如果该队伍的气球数大于上限 该队伍被淘汰.给了你队伍的气球数,你的气球可以给别人,问你最大可能的排名. (2 ≤ n ≤ 3 ...

  3. 【枚举】Southwestern Europe Regional Contest H - Sheldon Numbers

    https://vjudge.net/contest/174235#problem/H [题意] 求[x,y]之间有多少个Sheldon Number Sheldon Number是二进制满足以下条件 ...

  4. 【LeetCode Weekly Contest 26 Q4】Split Array with Equal Sum

    [题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/split-array-with-equal-sum/ ...

  5. 【LeetCode Weekly Contest 26 Q3】Friend Circles

    [题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/friend-circles/ [题意] 告诉你任意两个 ...

  6. 【LeetCode Weekly Contest 26 Q2】Longest Uncommon Subsequence II

    [题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/longest-uncommon-subsequence ...

  7. 【LeetCode Weekly Contest 26 Q1】Longest Uncommon Subsequence I

    [题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/longest-uncommon-subsequence ...

  8. 【LeetCode】从contest-21开始。(一般是10个contest写一篇文章)

    [LeetCode Weekly Contest 29][2017/04/23] 第17周 Binary Tree Tilt (3) Array Partition I (6) Longest Lin ...

  9. 【37.74%】【codeforces 725D】Contest Balloons

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. 《温故而知新》JAVA基础六

    多态(父子类之间) 对象的多种形态 引用多态 父类的引用可以指向本类对象 父类的引用可以指向子类的对象 方法的多态 创建本类对象时候,调用的方法是本类方法 创建子类对象时候,调用的方法为子类重写的方法 ...

  2. 扩展的GM命令

    命令 说明 例子 .rl all 重载核心所有自定义数据表   .rl item 重载item_template   .backup a 备份Auth数据库   .backup c 备份Charact ...

  3. 3.1 eureka自我保护

    故障现象: Down:是下线(掉线)的意思. 导致原因: 一句话:某时刻某一个微服务不可用了,eureka不会立刻清理,依旧会对该微服务的信息进行保存 什么是自我保护模式? 默认情况下,如果Eurek ...

  4. 由装饰者模式来深入理解Java I/O整体框架

    前言 Java里面的I/O这一部分看过很多遍,每次看完之后特别混乱,又是输入流,又是输出流,又是字符流,又是字节流,还有什么过滤流,缓冲流.每次看得我如入云里雾里,直到后面看了设计模式这一块,才算真正 ...

  5. Hadoop启动之后jps没有NameNode节点

    这是因为多次格式化namenode节点出现的问题 1.先运行stop-all.sh 2.删除原目录,即core-site.xml下配置的<name>hadoop.tmp.dir</n ...

  6. Python 小节回顾

    1.python程序是大小写敏感. 2.python中字符串是用单引号 ' 或双引号 " 括起来的任意文本. python中用 r '  ' 表示 ' ' 内部的字符串不转义. 3.在pyt ...

  7. 浅谈awk命令

    简介 awk是一个强大的文本分析工具,相对于grep.sed命令,awk在其对数据分析并生成报告时,显得尤为强大.简单来说awk就是把文件逐行的读入,然后将每行切片,再对切开的部分进行处理. awk有 ...

  8. 连接SQLsever数据库在C#中不能操作的问题

    最近小组成员在用C#连接数据库进行操作的时候,总是注册不起用户,提示为sql.client值不能为NULL,经过了一上午的百度查询,讨论,总是找不到问题所在,不得已去问了老师,老师是专业的软件工程师, ...

  9. windows10下安装mysql-8.0.15-winx64以及连接服务器过程中遇到的一些问题

    一.下载安装配置mysql-8.0.15 1.官网(https://dev.mysql.com/downloads/mysql/)下载zip包 2.解包到我的D:\mysql目录下 3.为mysql配 ...

  10. 常用模块Part(2)

    logging模块 hashlib模块 hashlib模块 Python的hashlib提供了常见的摘要算法,如MD5,SHA1等等. # 什么是摘要算法呢?摘要算法又称哈希算法.散列算法.它通过一个 ...