题目链接:http://codeforces.com/problemset/problem/40/E


妙啊...

  因为已经确定的格子数目严格小于了$max(n,m)$,所以至少有一行或者一列是空着的,那么除了这一行或者这一列的格子,其余的格子随意填,只要满足了当且对应的行(列)的积是$-1$就好了,用组合数算一算就好了,剩下的空着的一行或者一列用于收尾,可以发现它当且仅有一种放法。

  考虑无解:如果$n+m$为奇数,同时还要注意一下如果$n=1$,或者$m=1$的情况

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<vector>
 5 #include<cstdlib>
 6 #include<cmath>
 7 #include<cstring>
 8 using namespace std;
 9 #define maxn 2010
10 #define llg long long
11 #define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
12 llg n,m,k,ans,md;
13 llg c[maxn][maxn],a[maxn][maxn],d[maxn][maxn];
14 bool pd=true;
15 inline int getint()
16 {
17        int w=0,q=0; char c=getchar();
18        while((c<'0' || c>'9') && c!='-') c=getchar(); if(c=='-') q=1,c=getchar();
19        while (c>='0' && c<='9') w=w*10+c-'0', c=getchar(); return q ? -w : w;
20 }
21
22 llg check(llg x)
23 {
24     llg sum=0,V=1;
25     for (llg i=1;i<=m;i++) sum+=(a[x][i]!=0),V*=a[x][i];
26     if (sum==m && V==1) pd=false;
27     return sum;
28 }
29
30 int main()
31 {
32     yyj("Number");
33     cin>>n>>m;
34     if ((n+m)&1) {cout<<0; return 0;}
35     cin>>k;
36     for (llg i=1;i<=k;i++)
37     {
38         llg x=getint(),y=getint();
39         a[x][y]=getint();
40     }
41     if (n<m)
42     {
43         for (llg i=1;i<=n;i++)
44             for (llg j=1;j<=m;j++)
45                 d[j][i]=a[i][j];
46         swap(n,m);
47         for (llg i=1;i<=n;i++)
48             for (llg j=1;j<=m;j++)
49                 a[i][j]=d[i][j];
50     }
51     cin>>md;
52     c[1][0]=c[1][1]=1;
53     for (llg i=2;i<maxn;i++)
54     {
55         c[i][0]=1;
56         for (llg j=1;j<maxn;j++)
57             c[i][j]+=c[i-1][j]+c[i-1][j-1],c[i][j]%=md;
58     }
59     bool xian=0;
60     ans=1;
61     for (llg i=1;i<=n;i++)
62     {
63         llg s=check(i);
64         if (s==0 && !xian) xian=1;
65         else
66         {
67             llg kong=0,vz=0,vf=0,tot=0;
68             for (llg k=1;k<=m;k++) kong+=(a[i][k]==0),vz+=(a[i][k]==1),vf+=(a[i][k]==-1);
69             if (!kong) continue;
70             for (llg k=0;k<=kong;k++)
71             {
72                 if ((vf+k)%2)
73                     tot+=c[kong][k],tot%=md;
74             }
75             ans*=tot;ans%=md;
76         }
77     }
78     for (llg i=1;i<=m;i++)
79     {
80         llg V=1;
81         llg sum=0;
82         for (llg j=1;j<=n;j++) sum+=(a[j][i]==0),V*=a[j][i];
83         if (V==1 && sum==0) pd=false;
84     }
85     if (!pd) {cout<<0; return 0;}
86     cout<<ans;
87     return 0;
88 }
89 //各种细节令人发指!

转载于:https://www.cnblogs.com/Dragon-Light/p/6675564.html

Codeforces 40 E. Number Table相关推荐

  1. Codeforces40E[Number Table]

    Codeforces40E[Number Table] 解法一,如果有一维很小,可以考虑状压dp之类的,显然非常不优秀. 解法二,如果n*m较小,可以考虑,设出每个位置是否为-1,解xor线性方程组. ...

  2. CodeForces 991E Bus Number DFS+ 组合数

    CodeForces 991E Bus Number DFS+ 组合数 题目大意:给定一个数字,数字里出现的每一个数,都至少要用一个,问能组成多少个新数,不加前导零. input: 2028 outp ...

  3. Codeforces 55D Beautiful Number (数位统计)

    把数位dp写成记忆化搜索的形式,方法很赞,代码量少了很多. 下面为转载内容:  a positive integer number is beautiful if and only if it is  ...

  4. 第11期《codeforces 1167A - Telephone Number 题解 》

    题目描述如下: A. Telephone Number time limit per test 1 second memory limit per test 256 megabytes input s ...

  5. Codeforces 338 D. GCD Table

    http://codeforces.com/problemset/problem/338/D 题意: 有一张n*m的表格,其中第i行第j列的数为gcd(i,j) 给出k个数 问在这张表格中是否 有某一 ...

  6. 【CodeForces - 27E】Number With The Given Amount Of Divisors (数论,数学,反素数)

    题干: Given the number n, find the smallest positive integer which has exactly n divisors. It is guara ...

  7. codeforces 124A The number of positions

    点击打开链接 A. The number of positions time limit per test 0.5 second memory limit per test 256 megabytes ...

  8. Codeforces 1499D - The Number of Pairs(数论 + 组合计数)

    昨晚的cf没打,然后有人QQ问我D来着,正好在上毛概课可以划水就来口胡一波题解( 较为简单的套路题 ? (逃 简单实现一下就行了 ~ #include <bits/stdc++.h>usi ...

  9. Codeforces 991E. Bus Number (DFS+排列组合)

    解题思路 将每个数字出现的次数存在一个数组num[]中(与顺序无关). 将出现过的数字i从1到num[i]遍历.(i from 0 to 9) 得到要使用的数字次数数组a[]. 对于每一种a使用排列组 ...

最新文章

  1. R语言ggplot2可视化将图像标题(title)居中显示实战
  2. Microsoft Exchange Server 2010测试四成员DAG
  3. locust自己调试
  4. C++的坑真的多吗?
  5. 两个链接合并_如何找到两个链接列表的合并点
  6. UDK编辑器 49条小提示
  7. oracle数据库主键自增序列_【oracle】oracle数据库建立序列、使用序列实现主键自增...
  8. ant里面table嵌套子表格_ElementUI el-table行内编辑验证,动态增减行
  9. 886C. Petya and Catacombs#墓室探险(set集合)
  10. csdn 博客代码块显示复制按钮
  11. 国内ERP技术公司综合
  12. 如何设置qq支持临时会话聊天
  13. 数据结构零基础入门(初学者也能看懂):队列使用场景之无锁技术
  14. 获取多边形的最大最小坐标
  15. 写一个简易的手机APP
  16. 解释什么是啸叫,为什么会发生啸叫,啸叫的为何和如何防止啸叫
  17. python和java哪个好就业-计算机专业选Java和Python哪个前景好点?
  18. JQuery 日期选择框,精确到时分秒类型。
  19. Python老司机带你快速搞定日志分析工具
  20. Java实现 LeetCode 520 检测大写字母

热门文章

  1. Java只读服务器,在服务器端,JSP页面如何只读打开本地的word文件并显示在网页上...
  2. 华硕z170a如何开启m2_给Z170A 加个M.2 SSD,速度有点意思
  3. vue中如何实现用JavaScript调用函数的方式使用一个通用的通知组件
  4. python导入模块介绍_详解Python模块导入方法
  5. html5怎么改为vue_Vue.js 项目打包优化实践
  6. java string能存储多长_String 有多长?
  7. 计算机生物模拟试题,2017年高考理综生物部分模拟试题
  8. python构造数组并命名_Numpy数组追加命名列
  9. ashx获取input file 文件_前端战五渣学前端——FileReader预览本地文件
  10. java mcv_Spring和SpringMCV配置