zoukankan      html  css  js  c++  java
  • Petrozavodsk Summer Training Camp 2015 Day 2: Xudyh (TooSimple) Contest, Saturday, August 22, 2015 D题

    Problem D.Too Simple Input file: standard input Output file: standard output Time limit: 1 second Memory limit: 64 mebibytes Rhason Cheung had a simple problem, and asked Teacher Mai for help. But Teacher Mai thought this problem was too simple, sometimes naive. So she ask you for help. Teacher Mai has m functions f1, f2, . . . , fm : {1, 2, . . . , n} → {1, 2, . . . , n} (that means for all x ∈ {1, 2, . . . , n}, f(x) ∈ {1, 2, . . . , n}). But Rhason only knows some of these functions, and others are unknown. She wants to know how many different function series f1, f2, . . . , fm there are that for every i (1 ≤ i ≤ n), f1(f2(. . . fm(i))) = i. Two function series f1, f2, . . . , fm and g1, g2, . . . , gm are considered different if and only if there exist i (1 ≤ i ≤ m),j(1 ≤ j ≤ n),fi(j) 6= gi(j). Input First line of the input contains one integer T (1 ≤ T ≤ 50). For each test case, the first lines contains two numbers n and m (1 ≤ n, m ≤ 100). Then m lines follow. In i-th line, there is one number −1 or n space-separated integers. If there is only one number −1, the function fi is unknown. Otherwise the j-th number in the i-th line means fi(j). Output For each test case print the answer modulo 109 + 7. Example standard input standard output 1 3 3 1 2 3 -1 3 2 1 1

    题目分析:check一下合法的方案,对于连续的-1,设其长度为k,则k-1个是n!种排列,其余一种是唯一方案。

  • 相关阅读:
    shell中exec解析
    linux expr命令参数及用法详解
    Linux中变量#,#,@,0,0,1,2,2,*,$$,$?的含义
    Q_DISABLE_COPY
    lower_bound()函数
    滚动数组
    POJ 1159 Palindrome(LCS)
    C语言中short的意思
    ZOJ 2432 Greatest Common Increasing Subsequence(最长公共上升子序列+路径打印)
    ZOJ 1004 Anagrams by Stack(DFS+数据结构)
  • 原文地址:https://www.cnblogs.com/poler/p/7359483.html
Copyright © 2011-2022 走看看