zoukankan      html  css  js  c++  java
  • 【HDOJ6630】permutation 2(递推)

    题意:给定x,y,n,有标号从1到n的n个数组,求合法的排列个数模998244353使得

    1:p[1]=x

    2:p[n]=y

    3:相邻两项的差的绝对值<=2

    n<=1e5

    思路:

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef long long ll;
     4 typedef unsigned int uint;
     5 typedef unsigned long long ull;
     6 typedef pair<int,int> PII;
     7 typedef pair<ll,ll> Pll;
     8 typedef vector<int> VI;
     9 typedef vector<PII> VII;
    10 #define N  1100000
    11 #define M  4100000
    12 #define fi first
    13 #define se second
    14 #define MP make_pair
    15 #define pi acos(-1)
    16 #define mem(a,b) memset(a,b,sizeof(a))
    17 #define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)
    18 #define per(i,a,b) for(int i=(int)a;i>=(int)b;i--)
    19 #define lowbit(x) x&(-x)
    20 #define Rand (rand()*(1<<16)+rand())
    21 #define id(x) ((x)<=B?(x):m-n/(x)+1)
    22 #define ls p<<1
    23 #define rs p<<1|1
    24 
    25 const ll MOD=998244353,inv2=(MOD+1)/2;
    26       double eps=1e-6;
    27       int INF=1e9;
    28 
    29 int f[110000];
    30 
    31 int read()
    32 {
    33    int v=0,f=1;
    34    char c=getchar();
    35    while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
    36    while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
    37    return v*f;
    38 }
    39 
    40 
    41 
    42 int main()
    43 {
    44     int cas=read();
    45     f[1]=f[2]=f[3]=1;
    46     rep(i,4,100000) f[i]=(f[i-1]+f[i-3])%MOD;
    47     while(cas--)
    48     {
    49         int n=read(),x=read(),y=read();
    50         if(x>1) x++;
    51         if(y<n) y--;
    52         printf("%d
    ",f[y-x+1]);
    53     }
    54 
    55     return 0;
    56 }
  • 相关阅读:
    使用java.util.Timer来周期性的执行制定的任务
    Android中为APP创建快捷方式的原理(自己的理解)
    View.setTag()的作用
    用3种方法在 operator= 中处理“自我赋值”
    关于 const 成员函数
    复制构造函数 与 赋值操作函数
    Command 模式
    Mediator 模式
    求一棵普通树的两个结点的最低公共祖先
    Memento 模式
  • 原文地址:https://www.cnblogs.com/myx12345/p/11648619.html
Copyright © 2011-2022 走看看