hdu5399(2015多校9)--Too Simple

题目链接:点击打开链接

题目大意:有m个映射,从1到n映射到1到n,记为f1,f2,f3,,,fm,并且这些映射满足f1( f2( f3(,,,,fm(i) ) ) ) = i现在已知几个映射的值,还有几个映射是不知道的,问不知道的映射一共有几种可能的组合方式。

输入n m,之后m行,如果一行的第一个数为-1,代表这一个映射fi是不知道的,否则一行有n个数,第i行的第j个数字x代表fi(j) = x

问最终的种类(对1e9+7取余)

1、如果映射不是单射,也就是存在fi(x) = fi(y)并且x!=y,那么就不可能满足关系式,输出0

2、如果所有的映射都已经给出,那么判断是不是映射都符合条件,如果符合输出1,否则输出0

3、假设存在num个未知的映射,那么这num个未知的映射一定都是单射,我们要保证满足公式只需要对最小的一个映射进行调控,就可以了,之后的映射不论怎么样变化,都可以通过改变最小的映射,使得整体满足条件。所以对于一个映射的全排列n!种,然后n!*(num-1)

#include <cstdio>
#include <cstring>
#include <queue>
#include <set>
#include <vector>
#include <cmath>
#include <map>
#include <stack>
#include <time.h>
#include <algorithm>
using namespace std ;
#pragma comment(linker, "/STACK:102400000,102400000")
#define LL __int64
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
const int Mod = 1e9+7;
int vis[110] , a[110][110] ;
LL ans , s ;
int main() {
    int n , m , x , i , j , flag , num ;
    while( scanf("%d %d", &n, &m) !=EOF ) {
        for(i = 1 , s = 1 ; i <= n ; i++) s = s*i%Mod ;
        num = flag = 0 ;
        for(i = 1 ; i <= m ; i++) {
            memset(vis,0,sizeof(vis)) ;
            for(j = 1 ; j <= n ; j++) {
                scanf("%d", &a[i][j]) ;
                if( a[i][j] == -1 ) {
                    num++ ;
                    break ;
                }
                vis[ a[i][j] ]++ ;
                if( vis[ a[i][j] ] == 2 ) flag = 1 ;
            }
            if( j <= n ) continue ;
        }
        if( flag ) {
            printf("0\n") ;
            continue ;
        }
        if( num == 0 ) {
            for(i = 1 ; i <= n ; i++) {
                x = i ;
                for(j = m ; j > 0 ; j--)
                    x = a[j][x] ;
                if( x != i ) break ;
            }
            if( i <= n ) printf("0\n") ;
            else printf("1\n") ;
            continue ;
        }
        ans = 1 ;
        for(i = 1 ; i < num ; i++)
            ans = ans*s%Mod ;
        printf("%I64d\n", ans) ;
    }
    return 0 ;
}

版权声明:转载请注明出处:http://blog.csdn.net/winddreams

时间: 2024-08-05 21:00:40

hdu5399(2015多校9)--Too Simple的相关文章

2015 多校 #5 1007 MZL&#39;s simple problem

MZL's simple problem Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2541    Accepted Submission(s): 694 Problem Description A simple problemProblem DescriptionYou have a multiple set,and now th

HDU 5349(2015多校5)-MZL&#39;s simple problem(优先队列)

题目地址:HDU 5349 很水的优先队列就能搞好,只不过注意如果2操作结束后的队列为空,那么Max的值为-inf. #include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <sstream> #include <algorithm> #include <set&

HDU 5371 (2015多校联合训练赛第七场1003)Hotaru&#39;s problem(manacher+二分/枚举)

HDU 5371 题意: 定义一个序列为N序列:这个序列按分作三部分,第一部分与第三部分相同,第一部分与第二部分对称. 现在给你一个长为n(n<10^5)的序列,求出该序列中N序列的最大长度. 思路: 来自官方题解:修正了一些题解错别字(误 先用求回文串的Manacher算法,求出以第i个点为中心的回文串长度,记录到数组p中 要满足题目所要求的内容,需要使得两个相邻的回文串,共享中间的一部分,也就是说,左边的回文串长度的一半,要大于等于共享部分的长度,右边回文串也是一样. 因为我们已经记录下来以

HDU 5371 (2015多校联合训练赛第七场1003)Hotaru&amp;#39;s problem(manacher+二分/枚举)

pid=5371">HDU 5371 题意: 定义一个序列为N序列:这个序列按分作三部分,第一部分与第三部分同样,第一部分与第二部分对称. 如今给你一个长为n(n<10^5)的序列,求出该序列中N序列的最大长度. 思路: 来自官方题解:修正了一些题解错别字(误 先用求回文串的Manacher算法.求出以第i个点为中心的回文串长度.记录到数组p中 要满足题目所要求的内容.须要使得两个相邻的回文串,共享中间的一部分,也就是说.左边的回文串长度的一半,要大于等于共享部分的长度,右边回文串也

hdu 5288||2015多校联合第一场1001题

http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number of i (l<=i<=r) , that there's no j(l<=j<=r,j<>i) satisfy ai mod aj=0,now OO want to know ∑i

hdu5289||2015多校联合第一场1002贪心+RMQ

http://acm.hdu.edu.cn/showproblem.php?pid=5289 Problem Description Tom owns a company and he is the boss. There are n staffs which are numbered from 1 to n in this company, and every staff has a ability. Now, Tom is going to assign a special task to

hdu5348(2015多校5)--MZL&#39;s endless loop(搜索)

题目链接:点击打开链接 题目大意:给出n个点,m条无向边,现在要求将无向边变为有向边,要保证每个点的出度和入度的差不超过1 直接进行搜索,对每个点进行出度和入度的判断,如果出度大,就先进行反向的搜索(每搜索一条边u,v就认为这是一条v到u的有向边),反之,进行正向搜索(每搜到一条边u,v认为这是一条u到v的有向边),一直搜索到找不到边能继续为止. 注意: 1.已经使用过的边为了防止再次被遍历,可以修改head,head[u] = edge[i].next 2.注意自环,因为搜索是判断能不能继续向

hdu5379||2015多校联合第7场1011 树形统计

http://acm.hdu.edu.cn/showproblem.php? pid=5379 Problem Description Little sun is an artist. Today he is playing mahjong alone. He suddenly feels that the tree in the yard doesn't look good. So he wants to decorate the tree.(The tree has n vertexs, i

hdu5351(2015多校5)--MZL&#39;s Border(打表,,找规律)

题目链接:点击打开链接 题目大意:给出b1 = 'b' , b2 = 'a' , bi = b(i-1)b(i-2),将i-1和i-2链接起来,记录一个串的s[1-i] 和s[n-i+1-n]相同的话 Border,当i为最长是为LBorder,现在给让求在bn这个串上的前m个字符组成的子串的LBorder 通过计算可以发现,b字符串的前缀都是相同的,所以只要求出m的LBorder就行,和n是无关的,打表找出规律,找出对应不同的m,LBorder的值,因为存在大数,用java写 dp[i]第i层

hdu5353||2015多校联合第六场1001 贪心

http://acm.hdu.edu.cn/showproblem.php?pid=5353 Problem Description There are n soda sitting around a round table. soda are numbered from 1 to n and i-th soda is adjacent to (i+1)-th soda, 1-st soda is adjacent to n-th soda. Each soda has some candies