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. APIView的流程分析

     APIView的流程分析 1.入口,因为视图类的继承APIView()的 as_view()是一个绑定类的方法 2.进入as_view(),正好这个as_view()有个返回值 返回的是dispat ...

  2. 手写一个IOC容器

    链接:https://pan.baidu.com/s/1MhKJYamBY1ejjjhz3BKoWQ 提取码:e8on 明白什么是IOC容器: IOC(Inversion of Control,控制反 ...

  3. MySql-Mysql技术内幕~SQL编程学习笔记(N)

    1._rowid 类似Oracle的rowid mysql> ; +-------+----+----------------+-------------+---------------+--- ...

  4. C++中的字符串类

    1,本文分析 C++ 中的字符串,C 语言中的字符串利用的是 C 语言中的字符数组,  在 C 语言中没有真正意义上的字符串,利用了字符数组表示了字符串,最初设  计 C 语言仅仅是为了开发 Unix ...

  5. vue项目如何监听窗口变化,达到页面自适应?

    [自适应]向来是前端工程师需要解决的一大问题--即便作为当今非常火热的vue框架,也无法摆脱--虽然elementui.iview等开源UI组件库层出不穷,但官方库毕竟不可能满足全部需求,因此我们可以 ...

  6. C#设计模式:访问者模式(Vistor Pattern)

    一,访问者模式是用来封装一些施加于某种数据结构之上的操作.它使得可以在不改变元素本身的前提下增加作用于这些元素的新操作,访问者模式的目的是把操作从数据结构中分离出来. 二,代码 using Syste ...

  7. IDEA显示Run Dashboard窗口

    接下来在workspace.xml RunDashBoard节点中添加如下内容:<component name="RunDashboard"> 在代码中加入 <o ...

  8. Vue之指令和绑定

    一.v-once指令 <!DOCTYPE html> <html lang="zh"> <head> <meta charset=&quo ...

  9. C# List<Object>值拷贝

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Run ...

  10. Linux--用户与用户组--03

    用户管理: 1.useradd 创建用户 -c 指定用户描述 -d 指定家目录 -g 指定主组 -G 指定附加组 附加组可以有多个 -s 指定shell程序 特殊的/sbin/nologin--> ...