hdu5399 Too Simple(推论,分类讨论)

27 篇文章 0 订阅
9 篇文章 0 订阅

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

题解:http://blog.csdn.net/queuelovestack/article/details/47753497

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<stdlib.h>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#define exp 1e-10
using namespace std;
const int N = 105;
const int inf = 1000000000;
const int mod = 1000000007;
__int64 s[N];
bool v[N];
int w[N][N];
int dfs(int t,int x)
{
    if(t==1)
        return w[t][x];
    return dfs(t-1,w[t][x]);
}
int main()
{
    int n,m,i,j,k,x;
    bool flag;
    __int64 ans;
    s[0]=1;
    for(i=1;i<N;i++)
        s[i]=(s[i-1]*i)%mod;
    while(~scanf("%d%d",&n,&m))
    {
        flag=true;
        for(k=0,i=1;i<=m;i++)
        {
            scanf("%d",&x);
            if(x==-1)
                k++;
            else
            {
                memset(v,false,sizeof(v));
                v[x]=true;w[i][1]=x;
                for(j=2;j<=n;j++)
                {
                    scanf("%d",&x);
                    v[x]=true;
                    w[i][j]=x;
                }
                for(j=1;j<=n;j++)
                    if(!v[j])  //因为这一层的下标是上一层的数组值,所以上一层值必然是1~n 
                        break;
                if(j<=n)
                    flag=false;
            }
        }
        if(!flag)
            puts("0");
        else if(!k)  //没有-1的时候 
        {
            for(i=1;i<=n;i++)
                if(dfs(m,i)!=i)
                    break;
            if(i>n)
                puts("1");
            else
                puts("0");
        }
        else
        {
            for(ans=1,i=1;i<k;i++)
                ans=ans*s[n]%mod;
            printf("%I64d\n",ans);
        }
    }
    return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值