//给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. 点击按钮打开一个新的窗口 关键词(Intent, setData , putExtra , startActivity |Bundle)

    M3U8_Video_demo 项目 //------------------ 创建发送private void playVideo(String source, String title) { if ...

  2. svn 设置代理

    Memory4Young Do Not Repeat Yourself! SVN —— 如何设置代理 如果在使用SVN下载外网的资源时,出现这样的提示:No such host is known. 或 ...

  3. C++ Simple Message/Logging Class

    在 Qt的源码与Protobuf 的代码中,看到相同的简单消息(日志)输出的类实现,基本思路是使用宏定义,重载临时类对象,调用类方法或者通过析构函数自动调用输出方法,实现消息输出.这里以 Protob ...

  4. openjdk-alpine镜像无法打印线程堆栈和内存堆栈问题

    基于openjdk:8u171-alpine构建的java镜像,使用jstack命令打印线程的时候会提示以下错误: /opt # ps -ef PID USER TIME COMMAND 1 root ...

  5. SCI journals on Energy

    SCI journals on Energy Table of Contents 1. SCI- Clarivate - Thomson Reuters 1 SCI- Clarivate - Thom ...

  6. logging日志模块配置

    logging日志模块 日志级别 日志一共分成5个等级,从低到高分别是: 1)DEBUG 2)INFO 3)WARNING 4)ERROR 5)CRITICAL 说明: DEBUG:详细的信息,通常只 ...

  7. 【HIHOCODER 1163】 博弈游戏·Nim游戏

    描述 今天我们要认识一对新朋友,Alice与Bob. Alice与Bob总是在进行各种各样的比试,今天他们在玩一个取石子的游戏. 在这个游戏中,Alice和Bob放置了N堆不同的石子,编号1..N,第 ...

  8. laravel(4.2) +Zizaco

    操作步骤:https://github.com/Zizaco/entrust/tree/1.0 这篇博客说的蛮详细的:http://blog.boolw.com/?p=241 简化后的步骤 1.在根项 ...

  9. Computer (树形DP)

    A school bought the first computer some time ago(so this computer's id is 1). During the recent year ...

  10. POJ 2375 Cow Ski Area【tarjan】

    题目大意:一个W*L的山,每个山有个高度,当且仅当一个山不比它相邻(有公共边的格子)的山矮时能够滑过去,现在可以装化学电梯来无视山的高度滑雪,问最少装多少电梯使得任意两点都可到达 思路:最后一句话已经 ...