题意:给你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

最新文章

  1. css样式之border
  2. js实现无缝循环滚动
  3. 三种方法查看MySQL数据库的版本
  4. NOIP2010引水入城[BFS DFS 贪心]
  5. 通过IL分析C#中的委托、事件、Func、Action、Predicate之间的区别与联系
  6. @media 手机与IPAD与PC
  7. easyUI之Form(表单)组件
  8. LINQ简明教程:数据排序、分组、过滤
  9. 『HTML5梦幻之旅』-缤纷多姿的烟花效果
  10. 设定十分钟android在状态栏上集成的开源project推荐
  11. react使用map生成的元素,key的设定不对导致每次删除都删除最后一个
  12. [Sdoi2016]征途
  13. Spring @RequestAttribute
  14. Unity调用Windows对话框保存时另存为弹框
  15. mysql 的REPLAYCE语句
  16. ubuntu新建、删除用户
  17. 【Java】解析JScrollPane类的使用
  18. WinDbg使用学习
  19. truffle Dapp 搭建
  20. 洛谷5月月赛T30212 玩游戏 【分治NTT + 多项式求ln】

热门文章

  1. C# 查看本机安装的NET Framework 版本
  2. 华农oj Problem K: 负2进制【有技巧构造/待补】
  3. SQL表操作习题2 1~10题
  4. CSS的7种常用的垂直居中的方法
  5. UVa 816 (BFS求最短路)
  6. 信号驱动IO
  7. django book表单验证学习
  8. appium 几点总结(转)
  9. ElasticSearch refresh和flush的理解
  10. elasticsearch新加入节点不能识别问题