首页 > 其他分享 >HDU 5399 Too Simple

HDU 5399 Too Simple

时间:2022-11-09 19:33:40浏览次数:37  
标签:HDU ch Simple 5399 tot int ans I64d include


Problem Description

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)≠gi(j).


Input


n,m(1≤n,m≤100).

The following are  m lines. In  i-th line, there is one number  −1 or  n space-separated numbers.

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


109+7.


Sample Input

3 3
1 2 3
-1
3 2 1


 



Sample Output


1

Hint

The order in the function series is determined. What she can do is to assign the values to the unknown functions.




这题其实很简单,对于多于两个-1的情况不管之前那个怎么选,只要最后一个固定就可以保证,所以答案就是(n!)^(m-1) m是-1的个数

不过此题坑比较多,要注意判断

#pragma comment(linker, "/STACK:1024000000,1024000000") 
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<functional>
using namespace std;
typedef long long LL;
const LL base = 1e9 + 7;
const int maxn = 105;
LL T, n, m, f[maxn], a[maxn][maxn];

inline void read(int &x)
{
char ch;
while ((ch = getchar())<'0' || ch>'9');
x = ch - '0';
while ((ch = getchar()) >= '0' && ch <= '9') x = x * 10 + ch - '0';
}

int main()
{
//read(T);
for (int i = f[0] = 1; i <= 100; i++) f[i] = f[i - 1] * i % base;
while (scanf("%I64d%I64d", &n, &m) != EOF)
{
LL tot = 0, ans = 1;
for (int i = 1; i <= m; i++)
{
scanf("%I64d", &a[i][1]);
if (a[i][1] == -1) tot++;
else for (int j = 2; j <= n; j++)
{
scanf("%I64d", &a[i][j]);
for (int k = j - 1; k; k--) if (a[i][j] == a[i][k]) ans = 0;
}
}
for (int i = 1; i < tot; i++) ans = ans * f[n] % base;
if (tot == 0)
{
for (int i = 1; i <= n; i++) a[0][i] = i;
for (int i = m; i; i--)
for (int j = 1; j <= n; j++) a[0][j] = a[i][a[0][j]];
for (int i = 1; i <= n; i++) if (a[0][i] != i) ans = 0;
}
printf("%I64d\n", ans);
}
return 0;
}



标签:HDU,ch,Simple,5399,tot,int,ans,I64d,include
From: https://blog.51cto.com/u_15870896/5838619

相关文章

  • HDU 5402 Travelling Salesman Problem
    ProblemDescriptionn rowsand m columns.Thereisanon-negativenumberineachcell.TeacherMaiwantstowalkfromthetopleftcorner (1,1......
  • HDU 1272 小希的迷宫
    ProblemDescription上次Gardon的迷宫城堡小希玩了很久(见ProblemB),现在她也想设计一个迷宫让Gardon来走。但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向......
  • HDU 2242 考研路茫茫——空调教室
    ProblemDescription众所周知,HDU的考研教室是没有空调的,于是就苦了不少不去图书馆的考研仔们。Lele也是其中一个。而某教室旁边又摆着两个未装上的空调,更是引起人们无......
  • HDU 4041 Eliminate Witches!
    ProblemDescriptionKanameMadokaisaMagicalGirl(MahouShoujo/PuellaMagi).ThedutyofaMagicalGirlistoeliminateWitches(Majo).Thoughsoundshorrif......
  • HDU 1237 简单计算器
    ProblemDescription读入一个只包含+,-,*,/的非负整数计算表达式,计算该表达式的值。Input测试输入包含若干测试用例,每个测试用例占一行,每行不超过200个字......
  • HDU 4739 Zhuge Liang's Mines
    ProblemDescriptionIntheancientthreekingdomperiod,ZhugeLiangwasthemostfamousandsmartestmilitaryleader.HisenemywasShimaYi,whoalways......
  • HDU 3608 最长回文
    ProblemDescription给出一个只由小写英文字符a,b,c...y,z组成的字符串S,求S中最长回文串的长度.回文就是正反读都是一样的字符串,如aba,abba等 Inp......
  • HDU 5591 ZYB's Game
    ProblemDescription withhisclassmatesinhiking:ahostkeepsanumberin  loses,orthehostwilltellalltheplayersthatthenumbernowisbigger......
  • HDU 4433 locker
    ProblemDescriptionApasswordlockerwithNdigits,eachdigitcanberotatedto0-9circularly.Youcanrotate1-3consecutivedigitsupordownino......
  • HDU 5586 Sum
    ProblemDescriptionThereisanumbersequence ,youcanselectainterval[l,r]ornot,allthenumbers  willbecome ..Afterthat,thesumofnnumbers......