#include<stdio.h>
#include<string>
#include<map>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
const int N=105;
const int MOD=1e9+7;
int n,m,k;
bool vis[N];
int a[N][N];
int b[N];
long long check(){
for(int i=1;i<=n;i++) b[i]=i;
for(int i=m;i;i--)
for(int j=1;j<=n;j++)
b[j]=a[i][b[j]];
for(int i=1;i<=n;i++){
if(b[i]!=i) return 0;
}
return 1;
}
long long solve(){
bool ok=true;
int cnt=0;
for(int i=1;i<=m;i++){
scanf("%d",&a[i][1]);
if(a[i][1]==-1) cnt++;
else {
for(int j=2;j<=n;j++){
scanf("%d",&a[i][j]);
for(int k=j-1;k;k--) if(a[i][j]==a[i][k]) ok=false;
}
}
}
if(!ok) return 0;
if(cnt==0) return check();
long long tmp=1;
long long res=1;
for(int i=2;i<=n;i++) tmp=(tmp*i)%MOD;
for(int i=1;i<cnt;i++) res=(res*tmp)%MOD;
return res;
}
void rd(int&x){
char ch;
for(ch=getchar();ch<'0' || ch>'9';ch=getchar());
x=0;
for(;ch>='0' && ch<='9';ch=getchar()) x=x*10+ch-'0';
}
int main(){
#ifndef ONLINE_JUDGE
freopen("aaa","r",stdin);
#endif
int T;
while(~scanf("%d%d",&n,&m)){
printf("%I64d\n",solve());
}
return 0;
}
hdu5399 思考的细节比较多
最新推荐文章于 2018-06-15 13:15:57 发布