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

满足上面的条件的话,仅仅要有一个-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. 【http code】HTTP协议状态码详解(HTTP Status Code)

    参考资料: http://www.cnblogs.com/shanyou/archive/2012/05/06/2486134.html 1xx:请求收到,这些状态代码表示临时的响应. 2xx:操作成 ...

  2. 【Codeforces Round #422 (Div. 2) C】Hacker, pack your bags!(hash写法)

    接上一篇文章; 这里直接把左端点和右端点映射到vector数组上; 映射一个open和close数组; 枚举1..2e5 如果open[i]内有安排; 则用那个安排和dp数组来更新答案; 更新答案完之 ...

  3. COGS——T 1215. [Tyvj Aug11] 冗余电网

    http://www.cogs.pro/cogs/problem/problem.php?pid=1215 ★   输入文件:ugrid.in   输出文件:ugrid.out   简单对比时间限制: ...

  4. 华为:一张图看懂 HBase

    来自为知笔记(Wiz)

  5. ubuntu中开启、关闭防火墙

    1.关闭ubuntu的防火墙        ufw disable 开启防火墙 ufw enable 2.卸载了iptables        apt-get remove iptables 3.关闭 ...

  6. POJ1833 &amp; POJ3187 &amp; POJ3785 next_permutation应用

    要是没有next_permutation这个函数,这些题认为还不算特别水,只是也不一定,那样可能就会有对应的模板了. 反正正是由于next_permutation这个函数.这些题包含之前的POJ122 ...

  7. sublime配置python

    Sublime Text 2作为一款轻量级的编辑器,特点鲜明.方便使用,愈发受到普罗大众的喜爱.我个人近期也開始用了起来.同一时候,我近段时间还在学习Python的相关东西.所以開始用ST2来写Pyt ...

  8. 美团实习生电面之谈(成功拿到offer)

    3月底进行了美团的一次实习生面试(Java研发project师).当时顺利的通过一面.以下是我的一面: 1.CPU由哪些部分组成 2.线程和进程的差别 3.Java类载入机制 4.怎样实现一个字符串的 ...

  9. dedecms关键词维护里面字数多的词优先字数少的词的解决办法

    织梦后台的关键词维护默认的情况是字数少的词优先于字数多的词,比如我们有两个这样的词:创业.创业方向,第二个词包含了第一个词,在文章中如果出现“创业方向”这个词,默认情况下只会给创业两个字添加关键词超链 ...

  10. 学习《人人都是产品经理2.0:写给泛产品经理》高清中文PDF+苏杰(作者)

    <人人都是产品经理2.0--写给泛产品经理>将从人开始,以人结束,中间说事,以一个产品从无到有的过程为框架--想清楚.做出来.推出去,外加一章综合案例.其中,最重要的想清楚.做出来.推出去 ...