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. 所遇Oracle错误代码

    ORA-00905: 缺失关键字   少了空格或关键字写错 ORA-00922: 选项缺失或无效 错误原因:一般是语句的语法有问题.比如命名不对,关键字写错等等.对于非标准的命名,一般采用双引号来创建 ...

  2. 《深入浅出WPF》学习总结之控件与布局

    一.控件到底是什么 控件的本质是“数据+算法”——用户输入原始数据,算法处理原始数据并得到结果数据.问题就在于程序如何将结果数据展示给用户.同样一组数据,你可以使用LED阵列显示出来,或者是以命令行模 ...

  3. C语言第十一周作业

        这个作业属于哪个课程 C语言程序设计II 这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/computer-scienceclass3-2018/ ...

  4. notepad++通过调用cmd运行java程序

    notepad++运行java程序方法主要有下面两个: 通过插件NppExec运行(自行百度“notepad++运行java”) 通过运行 调用cmd编译执行java程序(下面详细讲解) 点击上面工具 ...

  5. 安装配置php及fastadmin

    FastAdmin教程之准备运行环境   一.Node.js http://nodejs.cn/download/ https://npm.taobao.org/mirrors/node/v8.4.0 ...

  6. 0ctf 2017 kernel pwn knote write up

    UAF due to using hlist_add_behind() without checking. There is a pair locker(mutex_lock) at delete_n ...

  7. 请写出一段Python代码实现删除一个list里面的重复元素?

    方法1:使用set函数  s=set(list),然后再list(s) 方法2:append    def delList(L): L1 = [] for i in L: if i not in L1 ...

  8. The Complex Inversion Formula. Bromwich contour.

    网址:http://www.solitaryroad.com/c916.html

  9. STL的容器哈希表

    C++ STL中,哈希表对应的容器是 unordered_map(since C++ 11).根据 C++ 11 标准的推荐,用 unordered_map 代替 hash_map. 与Map的区别 ...

  10. gradle配置国内阿里云镜像

    对单个项目生效,在项目中的build.gradle修改内容 buildscript { repositories { maven { url 'http://maven.aliyun.com/nexu ...