题意:给你m行个长度为 n的序列或者-1 -1代表这一行的序列不确定,然后让你找出有多少种情况满足对于每一个i 有f1(f2(⋯fm(i)))=i;

思路:分为三种情况:1,每行序列中有反复数输出0;2,存在-1的话一定有解且答案为n的阶乘的(-1的个数-1)次方;3。以上两种都不是的,推断一下可不能够,0 or 1

代码:

#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <cstdio>
#include <string>
#include <bitset>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <list>
#include <map>
#include <set>
#define sss(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define mem1(a) memset(a,-1,sizeof(a))
#define mem(a) memset(a,0,sizeof(a))
#define ss(a,b) scanf("%d%d",&a,&b)
#define s(a) scanf("%d",&a)
#define p(a) printf("%d\n", a)
#define INF 0x3f3f3f3f
#define w(a) while(a)
#define PI acos(-1.0)
#define LL long long
#define eps 10E-9
#define N 3000010
const LL mod = 1000000000+7;
const int SIGMA_SIZE=26;
const int MAXN=100010;
const int MAXNODE=600010;
using namespace std;
void mys(int& res) {
int flag=0;
char ch;
while(!(((ch=getchar())>='0'&&ch<='9')||ch=='-'))
if(ch==EOF) res=INF;
if(ch=='-') flag=1;
else if(ch>='0'&&ch<='9') res=ch-'0';
while((ch=getchar())>='0'&&ch<='9') res=res*10+ch-'0';
res=flag? -res:res;
}
void myp(int a) {
if(a>9)
myp(a/10);
putchar(a%10+'0');
}
/*************************THE END OF TEMPLATE************************/
int arr[110][110];
bool vis[110];
LL a[110];
int main() {
int n, m;
a[0]=1;
for(int i=1; i<=100; i++) a[i]=a[i-1]*i%mod;
w(~ss(n, m)){
bool flag_1 = false;
bool flag = false;
int x;
int sum_1=0;
LL pow_1=1;
for(int i=1; i<=m; i++){
if(!flag) mem(vis);
for(int j=1; j<=n; j++){
s(x);
if(x == -1){
sum_1 ++;
if(sum_1>1){
pow_1=(pow_1*a[n])%mod;
}
break;
}
if(vis[x]) flag = true;
vis[x] = true;
arr[i][j] = x;
}
}
if(flag) puts("0");
else if(!sum_1){
int i, tmp;
for(i=1; i<=n; i++){
tmp = i;
for(int j=m; j>=1; j--){
tmp = arr[j][tmp];
}
if(i!=tmp) break;
}
if(i>n) puts("1");
else puts("0");
}
else{
printf("%I64d\n",pow_1);
}
}
return 0;
}

)=i

hdu5399的更多相关文章

  1. [hdu5399 Too Simple]YY

    题意:m个{1,2...n}→{1,2...,n}的函数,有些已知有些未知,求对任意i∈{1,2,...,n},f1(f2(...(fm(i)))=i的方案总数,为了方便简记为F(i) 思路:如果存在 ...

随机推荐

  1. asp.net生成word文档服务器配置

    一.asp.net生成word文档,布署到正式的服务器上就出现           错误:System.Runtime.InteropServices.COMException (0x800A1098 ...

  2. (转)Ubuntu安装g++-4.8

    sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt-get update sudo apt-get install g++-4.8 ...

  3. PyCharm配置gitHub远程仓储

    在一个团队里,编码不能是闭门造车,git学起来: 1. GIT的基本介绍.安装及使用教程- @廖雪峰 2. pycharm配置github远程仓储- @谢小小XH

  4. HDU 4034 Graph Floyd最短路

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4034 题意: 给你一个最短路的表,让你还原整个图,并使得边最少 题解: 这样想..这个表示通过floy ...

  5. js实现当前日期显示

    写在前面: 在做项目中,经常会用到显示当前日期这个功能,在此,记录下来,方便日后查阅. 由于功能较简单,这里就直接将代码搬上来吧 <%-- Created by IntelliJ IDEA. U ...

  6. The expression being assigned to optional parameter `v2' must be a constant or default value

    今天写代码的时候遇到一个问题以前没有遇到过的问题,就是当我给一个对象参数赋值默认值的时候,报错了,代码如下 public void ShowOrHiddenKuang(bool isShow,Vect ...

  7. vs2012 ultimate 密钥

    Visual Studio Ultimate 2012 静态激活密钥,可以试一下. RBCXF-CVBGR-382MK-DFHJ4-C69G8

  8. 命令行解析函数:getopt/getopt_long

    参考: http://blog.csdn.net/zhangyang0402/article/details/5671410 http://www.cnblogs.com/gnuhpc/archive ...

  9. ubuntu10.10编译TQ2440的x86-qtopia-2.2.0具体问题总结及原因分析

    转: http://blog.csdn.net/zyxlinux888/article/details/6705481 http://www.cnblogs.com/liu_xf/archive/20 ...

  10. java中终止线程的三种方式

    在java中有三种方式可以终止线程.分别为: 1.  使用退出标志,使线程正常退出,也就是当run方法完成后线程终止.  2.  使用stop方法强行终止线程(这个方法不推荐使用,因为stop和sus ...