HDU 5399 Too Simple (2015-year School competition 9th game)

Source: Internet
Author: User

1. Title Description: Click to open the link

2. Problem-Solving ideas: a discussion of the situation. It was a really easy game, I thought it was (n!) ^ (cnt-1). Ultimate Infinity WA. There are several special cases that require additional judgment. First, if the input, there is a row is not-1 and there are two numbers mapped to the same number, then inevitably no solution, ans=0. Second, if there is no-1, you need to map from the first M function to the 1th function, and check to see if it really becomes a self-mapping at the end. The most likely scenario is that there is at least one-1, so the final answer is (n!) ^ (cnt-1).

3. Code:

#pragma COMMENT (linker, "/stack:1024000000,1024000000") #include <iostream> #include <algorithm># include<cassert> #include <string> #include <sstream> #include <set> #include <bitset># include<vector> #include <stack> #include <map> #include <queue> #include <deque># include<cstdlib> #include <cstdio> #include <cstring> #include <cmath> #include <ctime># Include<cctype> #include <functional>using namespace std; #define ME (s) memset (s,0,sizeof (s)) typedef long Long ll;typedef unsigned int uint;typedef unsigned long long ull;typedef pair <int, int> p;const int N=100+10;const    int mod=1e9+7;ll F[n],a[n][n];int Main () {int n,m;    F[0]=1;    for (int i=1;i<n;i++) f[i]= (f[i-1]*i)%mod;        while (~SCANF ("%d%d", &n,&m)) {ll ans=1,tot=0;            for (int i=0;i<m;i++) {scanf ("%i64d", &a[i][1]);            if (a[i][1]==-1) tot++; else for (int j=2;j< =n;j++) {scanf ("%i64d", &a[i][j]);  for (int k=j-1;k>=1;k--) if (a[i][k]==a[i][j]) ans=0;        If a row exists with two numbers mapped to the same number, no solution}} for (int i=1;i<tot;i++) ans= (ans*f[n])%mod;            if (!tot) {ll x[n];            for (int i=1;i<=n;i++) x[i]=i;            for (int. i=m-1;i>=0;i--) for (int j=1;j<=n;j++) {x[j]=a[i][x[j]];  } for (int i=1;i<=n;i++) if (x[i]!=i) ans=0;    Not self-mapping, no Solution} printf ("%i64d\n", ans); }}

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

HDU 5399 Too Simple (2015-year School competition 9th game)

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.