真的没有什么会写的东西了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. 6th-Python基础——集合、函数

    1.集合 主要作用: (1)去重 (2)关系测试,交集.差集difference().并集union().反向差集symmetric_difference().子集issubset().父集issup ...

  2. java 保存到mysql数据库中文乱码

    <property name="jdbcUrl">jdbc:mysql://localhost:3306/company?useUnicode=true&cha ...

  3. 使用Docker方式创建3节点的Etcd集群

    一.简要说明 二.运行容器 三.验证集群 四.运行截图 五.参考链接 一.简要说明     参考etcd官网文档, 在node1.node2.node3三个节点上,分别运行etcd容器,创建etcd集 ...

  4. Vue实现购物车小球动画

    思路: 1.因页面分组件分的比较细,由图可知是组件5到组件4的联动. 如果利用组件间通信需要 子组件5 -->组件3-->所有组件的父组件-->组件4, 层级略显复杂,所以使用了vu ...

  5. vue-先渲染dom载执行js

    价格判断v-if=“dataList”有数据的时候才渲染

  6. MATLAB绘图功能(2) 二维底层绘图修饰

    文末源代码 部分源代码   % x=0:0.1:2*pi; % y=sin(x); % plot(x,y); % line对象 % h = line([-pi:0.01:pi],sin([-pi:0. ...

  7. ranch 源码分析(三)

    接上ranch 源码分析(二) 上次讲到了ranch_conns_sup和ranch_acceptors_sup这2个ranch的核心模块,我们接着分析 首先查看ranch_conns_sup.erl ...

  8. SpringBoot之依赖注入DI

    相关注解: @Component @Service @Controller @Repository --------------------------------------------- @Inj ...

  9. Luffy之注册认证(容联云通讯短信验证)

    用户的注册认证 前端显示注册页面并调整首页头部和登陆页面的注册按钮的链接. 注册页面Register,主要是通过登录页面进行改成而成. 先构造前端页面 <template> <div ...

  10. ThinkPHP5.0源码学习之框架启动流程

    ThinkPHP5框架的启动流程图如下: ThinkPHP5的启动流程按照文件分为三步: 1.请求入口(public/index.php) 2.框架启动(thinkphp/start.php) 3.应 ...