Too Simple

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1214    Accepted Submission(s): 406

Problem Description
Rhason Cheung had a simple problem, and asked Teacher Mai for help. But Teacher Mai thought this problem was too simple, sometimes naive. So she ask you for help.

Teacher Mai has m functions f1,f2,⋯,fm:{1,2,⋯,n}→{1,2,⋯,n}(that means for all x∈{1,2,⋯,n},f(x)∈{1,2,⋯,n}). But Rhason only knows some of these functions, and others are unknown.

She wants to know how many different function series f1,f2,⋯,fm there are that for every i(1≤i≤n),f1(f2(⋯fm(i)))=i. Two function series f1,f2,⋯,fm and g1,g2,⋯,gm are considered different if and only if there exist i(1≤i≤m),j(1≤j≤n),fi(j)≠gi(j).

 
Input
For each test case, the first lines contains two numbers n,m(1≤n,m≤100).

The following are m lines. In i-th line, there is one number −1 or n space-separated numbers.

If there is only one number −1, the function fi is unknown. Otherwise the j-th number in the i-th line means fi(j).

 
Output
For each test case print the answer modulo 109+7.
 
Sample Input
3 3
1 2 3
-1
3 2 1
 
Sample Output
1

Hint

The order in the function series is determined. What she can do is to assign the values to the unknown functions.

 
 
一开始看起来很复杂,想了想发现只要保证最后一个函数是任意的,中间的其他函数都没问题。
但是有一个坑的情况是,可能一个任意函数也没有,全都是固定的函数,这时要验证这组函数是否可行。我们当时验证的顺序弄反,卡了一场,真是too simple。
最近做的题都是模拟题啊,,,太没技术含量了,,,,
 
 #include <cstdio>
#include <algorithm>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <stack>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cmath> using namespace std;
const long long MOD = 1e9+; int N,T,M;
int func[][],vis[];
long long nn; long long qpow(long long a,long long i,long long n)
{
if(i == ) return % n;
long long temp = qpow(a,i>>,n);
temp = temp * temp % n;
if( i& ) temp = temp * a % n;
return temp;
} long long mi(long long a,int t)
{
long long ans = ;
for(int i=;i<t;i++) {ans *= a;ans %= MOD;}
return ans;
} long long solve()
{
for(int i=;i<=N;i++)
{
int ans = i;
for(int j=M-;j>=;j--)
{
ans = func[j][ans-];
}
if(ans != i) return 0LL;
}
return 1LL;
} int main()
{
while(~scanf("%d%d",&N,&M))
{
long long cnt = 0LL,ans = 0LL;
nn = 1LL;
int flag = ;
for(int i=; i <= N;i++) {nn *= i; nn %= MOD;} for(int i=;i<M;i++)
{
memset(vis,,sizeof vis);
if(scanf("%d",&func[i][]) && (func[i][] == -))
{
cnt++;
}
else
{
vis[func[i][]]++;
for(int j=;j<N;j++)
{
scanf("%d",&func[i][j]);
if( vis[func[i][j]] ) flag = ;
else vis[func[i][j]]++;
}
}
} if(flag) ans = 0LL;
else if(cnt > ) { ans = mi(nn,cnt-); ans %= MOD;}
else
{
ans = solve();
} printf("%I64d\n",ans%MOD);
}
}
 

HDU5399-多校-模拟的更多相关文章

  1. NOIP2012 普及组真题 4.13校模拟

    考试状态: 我今天抽签看了洛谷的… 这我能怂???凶中带吉,我怕考试??我!不!怕! 看着整个机房的男同学们,我明白我是不会触发我的忌了.很好,开刷. A. [NOIP2012普及组真题] 质因数分解 ...

  2. NOIP2019普及级别模拟 3.30校模拟

    好吧我还是第一次写这种总结类的玩意… 考场心情…hmm…我没睡醒.是的是这样的,反正题都有两三个看错了或者没看懂… 最关键的是!!我!居!然!把!Freopen!写!在!了!程!序!最!后! 然后就和 ...

  3. [NOIP2018校模拟赛]T1 阶乘

    题目: 描述 有n个正整数a[i],设它们乘积为p,你可以给p乘上一个正整数q,使p*q刚好为正整数m的阶乘,求m的最小值. 输入 共两行. 第一行一个正整数n. 第二行n个正整数a[i]. 输出 共 ...

  4. 九校模拟——餐馆(restaurant)

    1 餐馆(restaurant) 1.1 题目背景 铜企鹅是企鹅餐馆的老板,他正在计划如何使得自己本年度收益增加. 1.2 题目描述 共有n 种食材,一份食材i 需要花ti 小时不间断地进行播种,施肥 ...

  5. [NOIP2018校模拟赛]T2矩阵分组 Matrix

    题目链接: 矩阵分组 分析: 这道题求的是两部分极差当中大的那个的最小值.对于这种求最值的问题,我们很自然(其实并没有)地想到二分答案. 这个题有两个结论: (好像当时看出来了第一个?然后发现下面都不 ...

  6. [NOIP2018校模拟赛]T1聚会 party

    题目链接: 聚会 分析: 设每个点到1号点的距离为dist_{i},每个点的权值为x_{i},目标点到1号点的距离为dist,权值为x,那么对于每一次查询,我们讨论三种情况: ① 目标家庭在区间左边( ...

  7. NOIP 模拟 七十一

    最后一场多校模拟赛,好像是信心赛??不过考的不行..最近难题比较多,对题目的难度把握不够好,经常出现简单题跳过的现象. 100+100+20+40 T1 签到题(qiandao) 如果一个点的度数不是 ...

  8. dir命令只显示文件名

    dir /b 就是ls -f的效果 1057 -- FILE MAPPING_web_archive.7z 2007 多校模拟 - Google Search_web_archive.7z 2083 ...

  9. AGC016题解

    呼我竟然真的去刷了016QwQ[本来以为就是个flag的233] 感觉AGC题目写起来都不是很麻烦但是确实动脑子qvq[比较适合训练我这种没脑子选手] 先扔个传送门:点我 A.Shrinking 题意 ...

随机推荐

  1. BP浅谈

    之前一直对BP的理解不透彻,这可不行,这个可是超经典的广泛应用在ML中的求偏导的方法.本博来自<神经网络与机器学习>P86页. 在用到bp的地方我们都是为了使用梯度下降法,并求出他的偏导数 ...

  2. eclipse 报错Version 1.6.0_45 of the JVM is not suitable for this product. Version:1.7 or greater is required

    最近离职来了一家新公司,之前的公司的开发IDE用的是IntelliJIDEA和SpringSourceToolSuit,自己在家里用的也是MyEclipse,所以使用eclipse的经验还是不足.结果 ...

  3. Literal 字面值 字面量 的理解

    Literal 字面值 字面量 Literal, 在程序语言中,指表示某种数据值的符码.如,123 是整数值符码, 3.14 是浮点值符码,abcd 是字串值符码,True, False, 是逻辑值符 ...

  4. WPF中的Bitmap与byte

    原文:WPF中的Bitmap与byte public MainWindow() { InitializeComponent(); byte[] b = GetPictureData(@"F: ...

  5. 算法相关——Java排序算法之快速排序(三)

    0. 前言 本系列文章将介绍一些常用的排序算法.排序是一个非常常见的应用场景,也是开发岗位面试必问的一道面试题,有人说,如果一个企业招聘开发人员的题目中没有排序算法题,那说明这个企业不是一个" ...

  6. 面试2——java基础1

    1.int和Integer的区别 1.Integer是int的包装类,int则是java的一种基本数据类型 2.Integer变量必须实例化后才能使用,而int变量不需要 3.Integer实际是对象 ...

  7. vue-cli 3.0 axios 跨域请求代理配置及生产环境 baseUrl 配置

    1. 开发环境跨域配置 在 vue.config.js 文件中: module.exports = { runtimeCompiler: true, publicPath: '/', // 设置打包文 ...

  8. [HAOI2017]方案数[组合计数、容斥、dp]

    题意 题目链接 分析 先考虑没有障碍怎么做,定义 f(i,j,k) 每一维走了 i,j,k 位的方案数,转移乘个组合数即可. 现在多了一些障碍,考虑容斥.实际我们走过的点都有严格的大小关系,所以先把所 ...

  9. easyui datagrid remoteSort的实现 Controllers编写动态的Lambda表达式 IQueryable OrderBy扩展

    EF 结合easy-ui datagrid 实现页面端排序 EF动态编写排序Lambda表达式 1.前端页面 var mainListHeight = $(window).height() - 20; ...

  10. beta阶段测试基本概况报告

    文件地址 测试基本信息                                                                                Bitmap 测试 ...