zoukankan      html  css  js  c++  java
  • hdu5399

    题意:给你m行个长度为 n的序列或者-1 -1代表这一行的序列不确定,然后让你找出有多少种情况满足对于每一个i 有f1(f2(⋯fm(i)))=i;

    思路:分为三种情况:1,每行序列中有反复数输出0;2,存在-1的话一定有解且答案为n的阶乘的(-1的个数-1)次方;3。以上两种都不是的,推断一下可不能够,0 or 1

    代码:

    #include <algorithm>
    #include <iostream>
    #include <sstream>
    #include <cstdlib>
    #include <cstring>
    #include <iomanip>
    #include <cstdio>
    #include <string>
    #include <bitset>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <cmath>
    #include <list>
    #include <map>
    #include <set>
    #define sss(a,b,c) scanf("%d%d%d",&a,&b,&c)
    #define mem1(a) memset(a,-1,sizeof(a))
    #define mem(a) memset(a,0,sizeof(a))
    #define ss(a,b) scanf("%d%d",&a,&b)
    #define s(a) scanf("%d",&a)
    #define p(a) printf("%d
    ", a)
    #define INF 0x3f3f3f3f
    #define w(a) while(a)
    #define PI acos(-1.0)
    #define LL long long
    #define eps 10E-9
    #define N 3000010
    const LL  mod = 1000000000+7;
    const int SIGMA_SIZE=26;
    const int MAXN=100010;
    const int MAXNODE=600010;
    using namespace std;
    void mys(int& res) {
        int flag=0;
        char ch;
        while(!(((ch=getchar())>='0'&&ch<='9')||ch=='-'))
            if(ch==EOF)  res=INF;
        if(ch=='-')  flag=1;
        else if(ch>='0'&&ch<='9')  res=ch-'0';
        while((ch=getchar())>='0'&&ch<='9')  res=res*10+ch-'0';
        res=flag?

    -res:res; } void myp(int a) { if(a>9) myp(a/10); putchar(a%10+'0'); } /*************************THE END OF TEMPLATE************************/ int arr[110][110]; bool vis[110]; LL a[110]; int main() { int n, m; a[0]=1; for(int i=1; i<=100; i++) a[i]=a[i-1]*i%mod; w(~ss(n, m)){ bool flag_1 = false; bool flag = false; int x; int sum_1=0; LL pow_1=1; for(int i=1; i<=m; i++){ if(!flag) mem(vis); for(int j=1; j<=n; j++){ s(x); if(x == -1){ sum_1 ++; if(sum_1>1){ pow_1=(pow_1*a[n])%mod; } break; } if(vis[x]) flag = true; vis[x] = true; arr[i][j] = x; } } if(flag) puts("0"); else if(!sum_1){ int i, tmp; for(i=1; i<=n; i++){ tmp = i; for(int j=m; j>=1; j--){ tmp = arr[j][tmp]; } if(i!=tmp) break; } if(i>n) puts("1"); else puts("0"); } else{ printf("%I64d ",pow_1); } } return 0; }



    )=i

  • 相关阅读:
    mysql的存储过程
    一份php高级工程师的面试题,我每天看一点点
    php的常用函数(持续更新)
    php 中文字符串截取
    php递归遍历文件目录
    ajax timeout 断网处理
    angular 刷新问题
    angular state中templateUrl 路径的模板
    angular请求传递不了数据
    截取字符串 substring substr slice
  • 原文地址:https://www.cnblogs.com/claireyuancy/p/7237465.html
Copyright © 2011-2022 走看看