首页 技术 正文
技术 2022年11月21日
0 收藏 449 点赞 4,102 浏览 1813 个字

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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,989
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,504
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,348
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,131
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,765
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,842