hdu5399Too Simple
来源:互联网 发布:mac怎么使用远程桌面 编辑:程序博客网 时间:2024/06/08 02:23
//给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 ;}
0 0
- hdu5399Too Simple
- simple
- Simple
- Simple introduction
- Simple Facotry
- Simple Computers
- Simple JAXP
- Simple Facotry
- simple stack
- Simple iptables
- Simple RSSReader
- Simple Facotry
- Simple Computers
- session-----simple
- Simple ant
- simple.cpp
- Simple Relection
- simple X11
- 2015-8-18数据结构-动态规划-矩阵乘法次数最少
- linux系统管理知识
- AWR stop working on linux x86 10.2.0.5
- selenium(webdriver)学习笔记2--打开指定路径的firefox
- db2导入导出表
- hdu5399Too Simple
- 猜数字小游戏[C语言][自制]
- 【Java】-基础-事件监听
- 字符串之简单模式匹配算法(BF)
- 简陋回合战斗实现。
- HDU 5317(RGCDQ-统计)
- hdu 1021 Fibonacci Again
- mysqld与mysqld_safe的区别
- Accelerated C++ 学习笔记2