每个函数都必须是一个排列,经过连续的一段确定函数后数字不能少.

满足上面的条件的话,仅仅要有一个-1函数特别的排列一下就能够满足要求,剩下的能够任意填

没有-1的话特判

Too Simple

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 789    Accepted Submission(s): 267

Problem Description
Rhason Cheung had a simple problem, and asked Teacher Mai for help. But Teacher Mai thought this problem was too simple, sometimes naive. So she ask you for help.



Teacher Mai has m functions f1,f2,⋯,fm:{1,2,⋯,n}→{1,2,⋯,n}(that
means for all x∈{1,2,⋯,n},f(x)∈{1,2,⋯,n}).
But Rhason only knows some of these functions, and others are unknown.



She wants to know how many different function series f1,f2,⋯,fm there
are that for every i(1≤i≤n),f1(f2(⋯fm(i)))=i.
Two function series f1,f2,⋯,fm and g1,g2,⋯,gm are
considered different if and only if there exist i(1≤i≤m),j(1≤j≤n),fi(j)≠gi(j).
 
Input
For each test case, the first lines contains two numbers n,m(1≤n,m≤100).



The following are m lines.
In i-th
line, there is one number −1 or n space-separated
numbers.



If there is only one number −1,
the function fi is
unknown. Otherwise the j-th
number in the i-th
line means fi(j).
 
Output
For each test case print the answer modulo 109+7.
 
Sample Input
3 3
1 2 3
-1
3 2 1
 
Sample Output
1
Hint
The order in the function series is determined. What she can do is to assign the values to the unknown functions.
 
Author
xudyh
 
Source
 

/* ***********************************************
Author :CKboss
Created Time :2015年08月19日 星期三 10时25分44秒
File Name :HDOJ5399.cpp
************************************************ */ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map> using namespace std; typedef long long int LL;
const LL mod=1e9+7LL;
const int INF=50000000; int n,m;
int f[110][110]; int cn;
int color[110]; bool COLOR(int x,int c)
{
if(color[x]==c) return false;
color[x]=c; cn++;
return true;
} LL QuickPow(LL a,LL n)
{
LL e=1;
while(n)
{
if(n&1) e=(a*e)%mod;
a=(a*a)%mod;
n/=2;
}
return e%mod;
} bool used[110]; LL jc(LL n)
{
LL ret=1;
for(int i=2;i<=n;i++)
ret=(ret*i)%mod;
return ret%mod;
} bool check_P(int x,int L=1,int R=m)
{
if(used[x]==true) return false;
int nx=x;
for(int i=R;i>=L;i--)
{
nx=f[i][nx];
}
if(nx==x)
{
if(used[x]==false)
{
used[x]=true;
return true;
}
else return false;
}
return false;
} bool check_Range(int L,int R)
{
memset(used,false,sizeof(used));
bool flag=true;
for(int i=1;i<=n&&flag;i++)
{
int nx=i;
for(int j=R;j>=L;j--)
{
nx=f[j][nx];
}
if(used[nx]==true) return false;
else used[nx]=true;
}
return true;
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); while(scanf("%d%d",&n,&m)!=EOF)
{
int nig=0;
bool check=true;
memset(color,0,sizeof(color)); for(int i=1;i<=m;i++)
{
scanf("%d",&f[i][1]);
if(f[i][1]==-1) nig++;
else
{
cn=0;
check=COLOR(f[i][1],i);
for(int j=2;j<=n;j++)
{
scanf("%d",&f[i][j]);
check=COLOR(f[i][j],i);
}
if(cn!=n) check=false;
}
} if(check==false)
{
puts("0");
}
else if(check&&nig==0)
{
/// tePan
memset(used,false,sizeof(used));
bool flag=true;
for(int i=1;i<=n&&flag;i++)
{
if(check_P(i)==false) flag=false;
}
if(flag==true) puts("1");
else puts("0");
}
else
{
//// (n!^(nig-1))
bool flag=true;
int Left=INF,Right=-INF;
f[m+1][1]=-1;
for(int i=1;i<=m+1&&flag;i++)
{
if(f[i][1]==-1)
{
if(Left!=INF&&Right!=-INF)
{
/// check;
flag=check_Range(Left,Right);
}
Left=INF; Right=-INF;
}
else
{
Left=min(Left,i); Right=max(Right,i);
}
}
if(flag==false) puts("0");
else printf("%lld\n",QuickPow(jc(n),nig-1)%mod);
}
} return 0;
}

HDOJ 5399 Too Simple的更多相关文章

  1. hdoj 5399 Tpp simple

    WA了一下午.... 1WA:T了,因为阶乘没打表所以时间超了.. 2WA,3WA:runtime error,检查的value数组开小了,应该是MAXN.. 4WA.5WA.6WA:改了改对cnt的 ...

  2. 构造 HDOJ 5399 Too Simple

    题目传送门 题意:首先我是懂了的,然后我觉得很难讲清楚就懒得写了,关键理解f1(f2(fm(i)))=i,不懂的戳这里构造:如果fi(j)不是映射到(1~n),重复或者不在范围内的肯定无解.还有没有- ...

  3. 【HDOJ 5399】Too Simple

    pid=5399">[HDOJ 5399]Too Simple 函数映射问题 给出m函数 里面有0~m个函数未知(-1) 问要求最后1~n分别相应仍映射1~n 有几种函数写法(已给定的 ...

  4. HDOJ 4974 A simple water problem

    A simple water problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

  5. HDU 5399 Too Simple(过程中略微用了一下dfs)——多校练习9

    Too Simple Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Probl ...

  6. HDOJ 4975 A simple Gaussian elimination problem.

    和HDOJ4888是一样的问题,最大流推断多解 1.把ISAP卡的根本出不来结果,仅仅能把全为0或者全为满流的给特判掉...... 2.在残量网络中找大于2的圈要用一种类似tarjian的方法从汇点開 ...

  7. 【HDOJ】2451 Simple Addition Expression

    递推,但是要注意细节.题目的意思,就是求s(x) = i+(i+1)+(i+2),i<n.该表达中计算过程中CA恒为0(包括中间值)的情况.根据所求可推得.1-10: 31-100: 3*41- ...

  8. 【HDOJ】1341 Simple Computers

    注意PC要与31. #include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 40 ...

  9. 【HDOJ】1497 Simple Library Management System

    链表. #include <cstdio> #include <cstring> #include <cstdlib> #define MAXM 1001 #def ...

随机推荐

  1. python3 geohash 导入错误及解决

    方法一: pip3 install  python-geohash 方法二: 1.保证 pip3 install geohash 包 2. 进入包的下载目录 /usr/local/lib/python ...

  2. P3168 [CQOI2015]任务查询系统(主席树)

    题目描述 最近实验室正在为其管理的超级计算机编制一套任务管理系统,而你被安排完成其中的查询部分.超级计算机中的任务用三元组(Si,Ei,Pi)描述,(Si,Ei,Pi)表示任务从第Si秒开始,在第Ei ...

  3. etTimeout来实现setInterval

    etTimeout来实现setInterval <script type="text/javascript"> function interval(func, w, t ...

  4. 服务器性能监控tips

    一.tops 第一行 当前时间/已运行时间/登录用户数/最近 5 10 15分钟平均负载(平均进程数 cat /proc/loadavg) 除了前3个数字表示平均进程数量外,后面的1个分数,分母表示系 ...

  5. js数组去重的常用方法总结

    最近几天朋友面试了几家,笔试题都做了关于数组去重的问题,自己在网上收集整理了一些去重的方法来学习下,感觉换不错哈!!!第一种方法: function oSort(arr){ var n = []; / ...

  6. lvs为何不能完全替代DNS轮询--转

    原文地址:http://mp.weixin.qq.com/s?__biz=MjM5ODYxMDA5OQ==&mid=2651959595&idx=1&sn=5f0633afd2 ...

  7. Firefox 浏览器有用的插件

    1.Undo Closed Tabs Button或Undo Closed Tabs Button (revived) 恢复关闭的标签页 2.NetVideohunter Video Download ...

  8. 【Redis实现运行状态下切换RDB备份至AOF备份】

    redis持久化方式有哪些?又有何区别? rdb:基于快照的持久化,速度更快,一般用作备份,主从复制也是依赖于rdb持久化功能. aof:以追加的方式记录redis操作日志的文件,可最大程度的保证re ...

  9. 在 Snoop 中使用 PowerShell 脚本进行更高级的 UI 调试

    原文:在 Snoop 中使用 PowerShell 脚本进行更高级的 UI 调试 版权声明:本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可.欢迎转载.使用.重新发布, ...

  10. 在Docker应用场景下 如何使用新技术快速实现DevOps

    在Docker应用场景下 如何使用新技术快速实现DevOps @Container容器技术大会是由国内容器技术社区DockOne组织的专为一线开发者和运维工程师设计的顶级容器技术会议,会议强调实践和交 ...