permutation 2

猜了发结论过了==

$N$个数的全排列,$p_{1}=x,p_{2}=y$要求$|p_{i+1}-p_{i}|<=2|$求满足条件的排列个数。

首先考虑$x=1,y=N$的情形,对任意$N$有$f(N)=f(N-1)+f(N-3)$成立,对于$x!=0$的情形,考虑先把$x$之前的数都排掉,对于$y!=N$考虑把$y$之后的数排完,这些数排列好像唯一???

然后就是$x+1~y-1$之间排,类似排$1~y-x-1$

#include<bits/stdc++.h>
using namespace std;
int T;
typedef long long ll;
ll A[];
ll mod=;
void init()
{
A[]=;
A[]=;
A[]=;
for(int i=;i<=;i++){
A[i]=(A[i-]+A[i-])%mod;
}
}
int main()
{
init();
scanf("%d",&T);
ll a,b;
ll N;
while(T--){
scanf("%lld%lld%lld",&N,&a,&b);
if(a>b)swap(a,b);
if(a!=)
a+=;
if(b!=N)
b-=;
cout<<A[b-a+]<<'\n';
} }

permutation 2的更多相关文章

  1. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  2. [LeetCode] Palindrome Permutation II 回文全排列之二

    Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...

  3. [LeetCode] Palindrome Permutation 回文全排列

    Given a string, determine if a permutation of the string could form a palindrome. For example," ...

  4. [LeetCode] Permutation Sequence 序列排序

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  5. [LeetCode] Next Permutation 下一个排列

    Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...

  6. Leetcode 60. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  7. UVA11525 Permutation[康托展开 树状数组求第k小值]

    UVA - 11525 Permutation 题意:输出1~n的所有排列,字典序大小第∑k1Si∗(K−i)!个 学了好多知识 1.康托展开 X=a[n]*(n-1)!+a[n-1]*(n-2)!+ ...

  8. Permutation test: p, CI, CI of P 置换检验相关统计量的计算

    For research purpose, I've read a lot materials on permutation test issue. Here is a summary. Should ...

  9. Permutation

    (M) Permutations (M) Permutations II (M) Permutation Sequence (M) Palindrome Permutation II

  10. Next Permutation

    Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...

随机推荐

  1. Docker之单多/机容器管理

    Compose是用于定义和运行多容器Docker应用程序的工具.通过Compose,您可以使用YAML文件来配置应用程序的服务.然后,使用一个命令,就可以从配置中创建并启动所有服务. Docker-C ...

  2. JS案例经验二

    一 关键词:鼠标事件的触发 可以在函数中指定让鼠标事件自动触发,而不是必须要鼠标滑过才触发,例如: main.onmouseover(); // 可以把该语句看做是鼠标滑过的模拟动作 main是DOM ...

  3. 洛谷 P5662 纪念品 & [NOIP2019普及组] (dp,完全背包)

    传送门 解题思路 本题首先要明白,在每一天时,最优策略是先进行操作2(卖),再进行操作1(买),才能是利益最大化. 本题很显然当只有两天时,是一个完全背包,就是把当日价钱当做体积,把明日价格和今日价格 ...

  4. Building and booting Nexus 5 kernel

    1. Downloading toolchain and setup. git clone https://android.googlesource.com/platform/prebuilts/gc ...

  5. 简述COOKIE和SESSION的区别与联系?

    cookie 和session 的区别:1.cookie数据存放在客户的浏览器上,session数据放在服务器上.2.cookie不是很安全,别人可以分析存放在本地的COOKIE并进行COOKIE欺骗 ...

  6. 【C#】获取"我的电脑"的名字,如This PC、这台计算机

    原文:[C#]获取"我的电脑"的名字,如This PC.这台计算机 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接: ...

  7. TCP/IP四层协议

    1.数据链路层 数据链路层实现了网卡接口的网络驱动程序,处理数据在物理媒介(以太网,令牌环)上的传输,常用协议包含ARP(地址解析协议),RARP(逆地址解析协议)两个协议,他们实现了IP地址和物理地 ...

  8. 18.Linux-CentOS系统根目录空间使用率100%问题?

    问题描述:发现服务器根目录爆满100%? 排查步骤:1.先检查文件索引节点iNode使用率情况,[root@localhost ~]# df -hTi2.查看无用文件是否居多:[root@localh ...

  9. Linux-date函数

    rhel7 date函数 显示本地时间?设定当前系统的时间,以一定格式显示当前时间,如X-X-X /X:X:X 使用man date命令查看关于date的使用方法 SYNOPSIS           ...

  10. TFServering和docker

    nvidia-docker安装:https://github.com/NVIDIA/nvidia-docker nvidia-docker的基本操作:https://blog.csdn.net/pan ...