On the too of the Nineth field of multi-school

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5399

Test instructions: give you m map, each argument x, corresponds to an F (x), this m map has some known, give you the mapping value from 1 to N, the remaining some do not know the mapping relationship, to you-1, ask to find out how many groups of matching mapping combinations, The requirements are: for I from 1 to N are satisfied F1 (F2 (.... FM (i))) =i

Idea: Open a brain hole found: If the number of 1 is more than one, then only the last 1 of the corresponding mapping is determined, the other is arbitrary, if the number of 1, only one, then the result is 1, if not 1, then also need to determine whether the mapping itself is not satisfied with the condition. Before doing this, it is necessary to consider whether this mapping is one by one corresponding, that is, whether this mapping is a function, only in order to continue the discussion-1 number of questions, if not one by one corresponding, then the different I corresponding to the same f (i) will not return to I.

The official explanation comes from a help understanding: first ask each F (i) is an arrangement, otherwise if an F (i)? map two numbers to the same number, then the last two numbers will have the same value. If there is one remaining position of-1, then this arrangement is the only certainty, assuming, so suppose there are C (c≥1)-1, then the answer is (n!) ^{c-1} is a viable solution.

Note the case where all functions are known.

Code:

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cctype>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <fstream>
#define DEBUG "Output for debug\n"
#define PI (ACOs (-1.0))
#define EPS (1E-8)
#define INF 0x3f3f3f3f
#define LL Long Long
using namespace Std;
const int MAXN = 100005;
int n, m;
int b[105][105];
CONST LL mod = 1e9 + 7;
ll a[105];
int check ()
{
int a[105];
int f[105];
for (int i=1;i<=n;i++)
A[i]=i;
for (int i=m; i>=1; i--)
{
for (int j=1; j<=n; j + +)
F[J]=B[I][A[J]];
for (int j=1; j<=n; j + +)
A[J]=F[J];
}
for (int i=1;i<=n;i++)
if (a[i]!=i)
return 0;
return 1;
}
int main () {
A[0] = 1;
for (int i = 1; i <=; i++)
A[i] = i * a[i-1]% mod;
while (scanf ("%d%d", &n, &m)!=eof)
{
int k = 0;
int flag = 0;
for (int i = 1; I <= m; i++)
{
int sum[111] = {0};
scanf ("%d", &b[i][1]);
if (b[i][1] = =-1) {
k++;
Continue
}
sum[b[i][1]]++;
for (int j = 2; J <= N; j + +)
{
scanf ("%d", &b[i][j]);
sum[b[i][j]]++;
if (Sum[b[i][j]] > 1) flag = 1;
}
}
if (flag) {
printf ("0\n");
Continue
}
if (k = = 0) {
printf ("%d\n", check ());
Continue
}
ll ans = 1;
k--;
while (k--) {
Ans = ans * a[n];
Ans%= MoD;
}
printf ("%i64d\n", ans);
}
return 0;
}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

On the too of the Nineth field of multi-school

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.