【HDU5187】contest
真的没有什么会写的东西了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的更多相关文章
- 【HDU5187】zhx's contest
[问题描述] 作为史上最强的刷子之一,zhx的老师让他给学弟(mei)们出n道题.zhx认为第i道题的难度就是i.他想要让这些题目排列起来很漂亮. zhx认为一个漂亮的序列{ai}下列两个条件均需满足 ...
- 【CF725D】Contest Balloons(贪心,堆)
题意:acm队伍可以得气球,相同气球数是一个排名.每个队伍有一个气球数上限,如果该队伍的气球数大于上限 该队伍被淘汰.给了你队伍的气球数,你的气球可以给别人,问你最大可能的排名. (2 ≤ n ≤ 3 ...
- 【枚举】Southwestern Europe Regional Contest H - Sheldon Numbers
https://vjudge.net/contest/174235#problem/H [题意] 求[x,y]之间有多少个Sheldon Number Sheldon Number是二进制满足以下条件 ...
- 【LeetCode Weekly Contest 26 Q4】Split Array with Equal Sum
[题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/split-array-with-equal-sum/ ...
- 【LeetCode Weekly Contest 26 Q3】Friend Circles
[题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/friend-circles/ [题意] 告诉你任意两个 ...
- 【LeetCode Weekly Contest 26 Q2】Longest Uncommon Subsequence II
[题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/longest-uncommon-subsequence ...
- 【LeetCode Weekly Contest 26 Q1】Longest Uncommon Subsequence I
[题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/longest-uncommon-subsequence ...
- 【LeetCode】从contest-21开始。(一般是10个contest写一篇文章)
[LeetCode Weekly Contest 29][2017/04/23] 第17周 Binary Tree Tilt (3) Array Partition I (6) Longest Lin ...
- 【37.74%】【codeforces 725D】Contest Balloons
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- public,private,protected,以及default时的区别
作用域 当前类 同一package 子孙类 其他package public √ √ √ ...
- 新建node工程
之前各种node工程都是东抄抄,西抄抄的. 用ng的cli之后,发现非常舒服.所以把node新建工程的种种记录一下. node+babel, 直接按es6标准写就好了, 不需要一定写ts再转码了( ...
- rocketmq ----> 学习笔记
官网:http://rocketmq.apache.org 1.环境搭建 准备: rocketmq-all-4.3.0-bin-release.zip 必须配置:JAVA_HOME=/home/rui ...
- java8中的时间处理
java8中关于时间的处理整理 package com.xb.utils; import java.time.*; import java.time.format.DateTimeFormatter; ...
- ES6 4个方法
var string = 'Yo' string.startsWith('Y') -> true startsWith()查找字符串是否是以某一个字段开始的 string ...
- List 常用方法
List 计算集合中某属性值的总和 list.Sum(ins=>ins.Field); Sort()方法,摘要:使用默认比较器对整个 System.Collections.Generic.Lis ...
- opencv3.0配置opencv_contrib
在opencv3.0中无法直接使用sift,surf等特征点检测算子,需要额外配置opencv_contrib. 在查看网上诸多教程,失败n次后,终于找到了正确的配置方式. visual studio ...
- Matlab:显(隐)式Euler和Richardson外推法变步长求解刚性问题
一.显示Euler 函数文件:Euler.m function f=Euler(h,Y) f(1,1)=Y(1)+h*(0.01-(1+(Y(1)+1000)*(Y(1)+1))*(0.01+Y(1) ...
- js中的object
JavaScript is an object-based language based on prototypes, rather than being class-based. this引用对象 ...
- Win10系列:C#应用控件进阶1
线形 线形没有内部空间,若要呈现一条直线,需要用Line对象的Stroke和StrokeThickness 属性分别为其轮廓的颜色及轮廓的粗细赋值,若不设置这两个属性,线形将不会呈现.绘制一条线形图形 ...