zoukankan      html  css  js  c++  java
  • hdu-5719 Arrange(组合数学)

    题目链接:

    Arrange

    Time Limit: 8000/4000 MS (Java/Others)   

     Memory Limit: 262144/262144 K (Java/Others)


    Problem Description
     
    Accidentally, Cupid, god of desire has hurt himself with his own dart and fallen in love with Psyche. 

    This has drawn the fury of his mother, Venus. The goddess then throws before Psyche a great mass of mixed crops.

    There are n heaps of crops in total, numbered from 1 to n

    Psyche needs to arrange them in a certain order, assume crops on the i-th position is Ai.

    She is given some information about the final order of the crops:

    1. the minimum value of A1,A2,...,Ai is Bi.

    2. the maximum value of A1,A2,...,Ai is Ci.

    She wants to know the number of valid permutations. As this number can be large, output it modulo 998244353.

    Note that if there is no valid permutation, the answer is 0.
     
    Input
    The first line of input contains an integer T (1T15), which denotes the number of testcases.

    For each test case, the first line of input contains single integer n (1n10^5).

    The second line contains n integers, the i-th integer denotes Bi (1Bin).

    The third line contains n integers, the i-th integer denotes Ci (1Cin).
     
    Output
    For each testcase, print the number of valid permutations modulo 998244353.
     
    Sample Input
    2
    3
    2 1 1
    2 2 3
    5
    5 4 3 2 1
    1 2 3 4 5
     
    Sample Output
    1
    0
     
     
    题意:

    有多少个[1,n]的全排列,满足b[],c[];
    b[i]为[1,i]的最小值,c[i]为[1,i]的最大值;
     
    思路:
     
    合法的b[],c[]应该是一个单调的函数;
    每次可以得到一个区间[b[i]+1,c[i]-1],再减去这个区间里面的已经被用的数就是这一位能选的数目了;相乘取模就行;
     
     
    AC代码:
     
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <map>
    
    using namespace std;
    
    #define For(i,j,n) for(int i=j;i<=n;i++)
    #define mst(ss,b) memset(ss,b,sizeof(ss));
    
    typedef  long long LL;
    
    template<class T> void read(T&num) {
        char CH; bool F=false;
        for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
        for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
        F && (num=-num);
    }
    int stk[70], tp;
    template<class T> inline void print(T p) {
        if(!p) { puts("0"); return; }
        while(p) stk[++ tp] = p%10, p/=10;
        while(tp) putchar(stk[tp--] + '0');
        putchar('
    ');
    }
    
    const LL mod=998244353;
    const double PI=acos(-1.0);
    const LL inf=1e18;
    const int N=1e5+10;
    const int maxn=1e3+10;
    const double eps=1e-6;
    
    int b[N],c[N];
    
    int main()
    {
            int t;
            read(t);
            while(t--)
            {
                int n;
                read(n);
                For(i,1,n)read(b[i]);
                For(i,1,n)read(c[i]);
                LL ans=1;
                int cnt=0;
                For(i,1,n)
                {
                    if(i==1)
                    {
                        if(b[i]!=c[i]){ans=0;break;}
                        else cnt++;
                        continue;
                    }
                    if(c[i]<i||b[i]>n-i+1){ans=0;break;}
                    if(b[i]>b[i-1]||c[i]<c[i-1]||b[i]>c[i]){ans=0;break;}                
                    if(b[i]<b[i-1]&&c[i]==c[i-1])cnt++;
                    else if(c[i]>c[i-1]&&b[i]==b[i-1])cnt++;
                    else if(c[i]==c[i-1]&&b[i]==b[i-1])
                    {
                        int len=c[i]-b[i]+1-cnt;
                        cnt++;
                        ans=ans*(LL)len%mod;
                    }
                    else {ans=0;break;}
                }
                cout<<ans<<"
    ";
            }
            return 0;
    }
    

      

  • 相关阅读:
    互联网改变的产业 汽车 x 互联网 = 汽车革命
    我有一个实现HMI触摸屏的资源【4418开发平台】降d成本
    iTOP-4412开发板裸机开发环境文档分享
    2019年最受欢迎iTOP-4418开发板_新产品研发必备利器
    安卓触控一体机为什么得到大家认可?远比Windows系统一体机大受欢迎
    新手入门嵌入式学习单片机?stm32?树莓派?4412开发板资料大汇报-基础了解
    iTOP-4418开发板-Qt系统下运行摄像头测试程序
    iTOP-4418/6818开发板-QtE4.7WIFI_MT6620热点
    iTOP-4412开发板-使用PartitionManager分区之后tf卡无法识别
    迅为iTOP-4418/6818开发板-MiniLinux-GPS使用文档
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5680604.html
Copyright © 2011-2022 走看看