hdu5399Too Simple
//给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的更多相关文章
- PHP设计模式(一)简单工厂模式 (Simple Factory For PHP)
最近天气变化无常,身为程序猿的寡人!~终究难耐天气的挑战,病倒了,果然,程序猿还需多保养自己的身体,有句话这么说:一生只有两件事能报复你:不够努力的辜负和过度消耗身体的后患.话不多说,开始吧. 一.什 ...
- Design Patterns Simplified - Part 3 (Simple Factory)【设计模式简述--第三部分(简单工厂)】
原文链接:http://www.c-sharpcorner.com/UploadFile/19b1bd/design-patterns-simplified-part3-factory/ Design ...
- WATERHAMMER: A COMPLEX PHENOMENON WITH A SIMPLE SOLUTION
开启阅读模式 WATERHAMMER A COMPLEX PHENOMENON WITH A SIMPLE SOLUTION Waterhammer is an impact load that is ...
- BZOJ 3489: A simple rmq problem
3489: A simple rmq problem Time Limit: 40 Sec Memory Limit: 600 MBSubmit: 1594 Solved: 520[Submit] ...
- 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 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- 设计模式之简单工厂模式Simple Factory(四创建型)
工厂模式简介. 工厂模式专门负责将大量有共同接口的类实例化 工厂模式可以动态决定将哪一个类实例化,不必事先知道每次要实例化哪一个类. 工厂模式有三种形态: 1.简单工厂模式Simple Factory ...
- HDU 5795 A Simple Nim 打表求SG函数的规律
A Simple Nim Problem Description Two players take turns picking candies from n heaps,the player wh ...
- 关于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交叉 ...
随机推荐
- PRJ0003 : Error spawning 'midl.exe'
原因:出现该错误的是由于:C:\Program Files\Microsoft SDKs\Windows\v6.0A midl.exe 和midlc.exe缺失. 解决方法:从别人电脑上拷贝这个两个文 ...
- 微信小程序工具真机调试提示page "xxx/xxx/xxx" is not found
解决方法: pages对象添加该页面
- 遇到的django问题
问题1: No migrations to apply 删除了migrations中0001_initial.py文件,重新执行 python manage.py makemigrations pyt ...
- c++_分巧克力(75分)
#include <iostream> using namespace std; int n,k; ],w[]; bool fen(int bian){ ; ;i<n;i++){ c ...
- 条款33:避免遮掩继承而来的名称(Avoiding hiding inherited names)
NOTE: 1.derived classes 内的名称会遮掩base classes内的名称.在public继承下从来没有人希望如此. 2.为了让被遮掩的名称再见天日,可使用using 声明方式或转 ...
- systemverilog:task
1.task declaration 个人喜欢ANSI C格式的声明: task mytask(output int x,input logic y); ...... endtask 注意端口列表的方 ...
- 周三面试Python开发,这几道Python面试题差点答错,Python面试题No7
第1题:阅读下面的代码,默读出A0,A1至An的最终值. A0 = dict(zip(('a','b','c','d','e'),(1,2,3,4,5))) A1 = range(10) A2 = [ ...
- Eclipse设置反编译插件
有些项目我们想看看引入的包的源码的时候,因为打包好的.class文件的内容我们是看不懂的,但是又懒得去找源码文件的时候,就会用到反编译工具. 步骤: 1.安装反编译插件. 2.设置使用的反编译工具. ...
- laravel count distinct
$result->count(\DB::raw("distinct(material_id)"));
- 如何在小程序自定义组件和动态传入数据小demo
在开发过程中,我们会将页面常用功能抽象为一个组件,这样既方便又可以避免代码冗余.小程序中也提供了自定义组件,了解Vue的伙伴们会发现其实和Vue的组件化很相似.这里用返回顶部功能来说说如何自定义组件, ...