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

满足上面的条件的话,仅仅要有一个-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. Systemd曝3漏洞,大部分Linux将受到攻击

    Linux 系统与服务管理工具 Systemd 被曝存在 3 大漏洞,影响几乎所有 Linux 发行版. Systemd 是 Linux 系统的基本构建块,它提供了对系统和服务的管理功能,以 PID ...

  2. awk 基础的用法

    基本的awk执行过程#passwd文件的第二行的第一列和第二列[root@oldboyedu01-nb ~]# awk -F ":" 'NR==2{print $1,$2}' /e ...

  3. python 爬虫简介

    初识Python爬虫 互联网 简单来说互联网是由一个个站点和网络设备组成的大网,我们通过浏览器访问站点,站点把HTML.JS.CSS代码返回给浏览器,这些代码经过浏览器解析.渲染,将丰富多彩的网页呈现 ...

  4. LocalDateTime与mysql日期类型的交互(基于mybatis)

    众所周知,在实体Entity里面,可以使用Java.sql.Date.java.sql.Timestamp.java.util.Date来映射到数据库的date.timestamp.datetime等 ...

  5. 三种记录 MySQL 所执行过的 SQL 语句的方法

    程式 Debug 有時後從前面第一行追起來很辛苦(程式碼太多或 compile 過), 另一種做法就是從後面追起來, 反正最後寫入的是 DB, 那就從 DB 開始往前推, 所以就是要抓程式是執行哪些 ...

  6. uvalive 6669 hidden tree(好壮压dp)

    题目见option=com_onlinejudge&Itemid=8&page=show_problem&problem=4681">here 题意:给一个序列 ...

  7. cocos2d-x 显示触摸操作(显示水波点击效果,用于视频演示)

    昨天刚刚參加玩游戏设计大赛, 积累了一些东西. 接下去将会逐个分享出来. 首先是显示触摸操作. 由于要演示我们的作品.使用试玩过程中, 假设没办法显示我们的触摸操作(像录制视频一样, 点击了屏幕某点, ...

  8. 百度LBS开放平台个性化地图 制作一款独一无二的地图

    百度LBS开放平台个性化地图  制作一款独一无二的地图 天天用百度地图的亲们是否已不再满足仅仅看例如以下的地图样式了呢? 默认百度地图样式 是否特别渴望看特别不一样的地图呢.如带京城81号气息的午夜蓝 ...

  9. DDR工作原理

    DDR SDRAM全称为Double Data Rate SDRAM,中文名为“双倍数据流SDRAM”.DDR SDRAM在原有的SDRAM的基础上改进而来.也正因为如此,DDR能够凭借着转产成本优势 ...

  10. Understanding IIS Bindings, Websites, Virtual Directories, and lastly Application Pools

    In a recent meeting, some folks on my team needed some guidance on load testing the Web application ...