//给m个函数
//其相应是自变量x属于{1,2,...n}
//f(x)属于{1,2...3}
//给出当中一些函数,问有多少种不同的函数集合使得
//1<=i<=n f1(f2(f3...fm(i))) = i
//直接为(m!)^(sum-1) sum为不知道的函数个数
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std ;
const int maxn = 110 ;
typedef long long ll ;
const ll mod = 1e9+7 ;
int map[maxn][maxn] ;
int vis[maxn];
int a[maxn] ;
int main()
{
//freopen("in.txt" ,"r" ,stdin) ;
//freopen("out.txt","w" ,stdout);
int n , m ;
int t = 0 ;
while(~scanf("%d%d" ,&m , &n))
{
int sum = 0 ;
int flag = 0 ;
for(int i = 1;i <= n;i++)
{
memset(vis , 0 , sizeof(vis)) ;
int tmp ;
scanf("%d" , &tmp);
if(tmp == -1)
sum++;
else
{
map[i][1] = tmp;
if(tmp < 1 || tmp > m || vis[tmp])flag = 1;
for(int j = 2;j <= m;j++)
{
scanf("%d" , &map[i][j]) ;
if(map[i][j] < 1 || map[i][j] > m || vis[map[i][j]])
flag = 1;
vis[map[i][j]] = 1;
}
}
}
if(flag)
{
puts("0");
continue ;
}
if(sum)
{
ll ans = 1;
sum--;
ll tmp = 1 ;
for(ll i = 1;i <= m;i++)
tmp = (tmp*i)%mod ;
while(sum--)
ans = (ans*tmp)%mod ;
printf("%lld\n" , ans) ;
continue ;
}
for(int i = 1;i <= m;i++)
a[i] = i ;
for(int i = n;i > 0;i--)
for(int j = 1;j <= m;j++)
a[j] = map[i][a[j]] ;
flag = 0 ;
for(int i = 1;i <= m;i++)
if(a[i] != i)
{
flag = 1;
break ;
}
if(flag)puts("0");
else puts("1");
}
return 0 ;
}

hdu5399Too Simple的更多相关文章

  1. PHP设计模式(一)简单工厂模式 (Simple Factory For PHP)

    最近天气变化无常,身为程序猿的寡人!~终究难耐天气的挑战,病倒了,果然,程序猿还需多保养自己的身体,有句话这么说:一生只有两件事能报复你:不够努力的辜负和过度消耗身体的后患.话不多说,开始吧. 一.什 ...

  2. Design Patterns Simplified - Part 3 (Simple Factory)【设计模式简述--第三部分(简单工厂)】

    原文链接:http://www.c-sharpcorner.com/UploadFile/19b1bd/design-patterns-simplified-part3-factory/ Design ...

  3. WATERHAMMER: A COMPLEX PHENOMENON WITH A SIMPLE SOLUTION

    开启阅读模式 WATERHAMMER A COMPLEX PHENOMENON WITH A SIMPLE SOLUTION Waterhammer is an impact load that is ...

  4. BZOJ 3489: A simple rmq problem

    3489: A simple rmq problem Time Limit: 40 Sec  Memory Limit: 600 MBSubmit: 1594  Solved: 520[Submit] ...

  5. Le lié à la légèreté semblait être et donc plus simple

    Il est toutefois vraiment à partir www.runmasterfr.com/free-40-flyknit-2015-hommes-c-1_58_59.html de ...

  6. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  7. 设计模式之简单工厂模式Simple Factory(四创建型)

    工厂模式简介. 工厂模式专门负责将大量有共同接口的类实例化 工厂模式可以动态决定将哪一个类实例化,不必事先知道每次要实例化哪一个类. 工厂模式有三种形态: 1.简单工厂模式Simple Factory ...

  8. HDU 5795 A Simple Nim 打表求SG函数的规律

    A Simple Nim Problem Description   Two players take turns picking candies from n heaps,the player wh ...

  9. 关于The C compiler "arm-none-eabi-gcc" is not able to compile a simple test program. 的错误自省...

    在 GCC ARM Embedded https://launchpad.net/gcc-arm-embedded/ 上面下载了个arm-none-eabi-gcc 用cmake 编译时 #指定C交叉 ...

随机推荐

  1. python+selenium自动化登录dnf11周年活动界面领取奖励登录部分采坑总结[1]

    背景: Dnf的周年庆活动之一,游戏在6月22日 06:00~6月23日 06:00之间登陆过游戏后可以于6月25日 16:00~7月04日 06:00领取奖励 目标:连续四天自动运行脚本,自动领取所 ...

  2. Node.js实现简单的爬取

    学习[node.js]也有几天时间了,所以打算写着练练手:索然我作为一个后端的选手,写起来还有那么一丝熟悉的感觉.emmm~~  ‘货’不多讲 ,开搞........ 首先是依赖选择: 代码块如下: ...

  3. C字符串指针遇到的问题

    看下面的示例代码: int main() { char *ptr = "GeeksQuiz"; printf("%c\n", *&*&*ptr) ...

  4. laravel 框架发送邮件

    http://www.jb51.net/article/121647.htm https://www.cnblogs.com/yxhblogs/p/5998463.html http://www.ji ...

  5. ubuntu18.04 server配置静态ip

    最新发布的ubuntu18.04 server,启用了新的网络工具netplan,对于命令行配置网络参数跟之前的版本有比较大的差别,现在介绍如下:1.其网络配置文件是放在/etc/netplan/50 ...

  6. uwsgs loading shared libraries: libicui18n.so.58 异常处理

    背景 想使用 ningx + uwsgi + flask 搭建 python 应用环境 Python使用的是anaconda3(pyhton 3.6) 依赖包安装完毕,但是执行 uwsgi 的时候出现 ...

  7. 关于最新版本react-native0.59.x构建的问题解决方案

    react-native的版本更新是真的快,几乎几天就是一个小版本,然而在这个过程中,对于新手来说,成功构建一个,并跑起来的项目,还是有一定难度的,各种问题,一不小心,你就会发现你的时间全部都浪费在了 ...

  8. LeetCode(77) Combinations

    题目 Given two integers n and k, return all possible combinations of k numbers out of 1 - n. For examp ...

  9. Java学习之正则表达式

    Java正则表达式字符串模式. 正则表达式可以用来搜索.编辑和处理文本. 正则表达式不尽限于一种语言,但在每一种语言中又细微的差别. java.util.regex包中主要有这3个类: Pattern ...

  10. ELK的简单安装使用

    ELK ELK是什么? Elasticsearch LogStash Kibana     1,简单的安装 我采用的是本地window环境: 下载的包如下:   首先安装的是jdk8,安装完成之后,设 ...