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


妙啊...

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

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

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<cstring>
using namespace std;
#define maxn 2010
#define llg long long
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg n,m,k,ans,md;
llg c[maxn][maxn],a[maxn][maxn],d[maxn][maxn];
bool pd=true;
inline int getint()
{
int w=,q=; char c=getchar();
while((c<'' || c>'') && c!='-') c=getchar(); if(c=='-') q=,c=getchar();
while (c>='' && c<='') w=w*+c-'', c=getchar(); return q ? -w : w;
} llg check(llg x)
{
llg sum=,V=;
for (llg i=;i<=m;i++) sum+=(a[x][i]!=),V*=a[x][i];
if (sum==m && V==) pd=false;
return sum;
} int main()
{
yyj("Number");
cin>>n>>m;
if ((n+m)&) {cout<<; return ;}
cin>>k;
for (llg i=;i<=k;i++)
{
llg x=getint(),y=getint();
a[x][y]=getint();
}
if (n<m)
{
for (llg i=;i<=n;i++)
for (llg j=;j<=m;j++)
d[j][i]=a[i][j];
swap(n,m);
for (llg i=;i<=n;i++)
for (llg j=;j<=m;j++)
a[i][j]=d[i][j];
}
cin>>md;
c[][]=c[][]=;
for (llg i=;i<maxn;i++)
{
c[i][]=;
for (llg j=;j<maxn;j++)
c[i][j]+=c[i-][j]+c[i-][j-],c[i][j]%=md;
}
bool xian=;
ans=;
for (llg i=;i<=n;i++)
{
llg s=check(i);
if (s== && !xian) xian=;
else
{
llg kong=,vz=,vf=,tot=;
for (llg k=;k<=m;k++) kong+=(a[i][k]==),vz+=(a[i][k]==),vf+=(a[i][k]==-);
if (!kong) continue;
for (llg k=;k<=kong;k++)
{
if ((vf+k)%)
tot+=c[kong][k],tot%=md;
}
ans*=tot;ans%=md;
}
}
for (llg i=;i<=m;i++)
{
llg V=;
llg sum=;
for (llg j=;j<=n;j++) sum+=(a[j][i]==),V*=a[j][i];
if (V== && sum==) pd=false;
}
if (!pd) {cout<<; return ;}
cout<<ans;
return ;
}
//各种细节令人发指!

Codeforces 40 E. Number Table的更多相关文章

  1. Codeforces 55D Beautiful Number

    Codeforces 55D Beautiful Number a positive integer number is beautiful if and only if it is divisibl ...

  2. Codeforces 40E Number Table - 组合数学

    题目传送门 传送门I 传送门II 题目大意 给定一个$n\times m$的网格,每个格子上要么填$1$,要么填$-1$,有$k$个位置上的数是已经填好的,其他位置都是空的.问有多少种填法使得任意一行 ...

  3. Codeforces 448 D. Multiplication Table

    二分法判断答案 D. Multiplication Table time limit per test 1 second memory limit per test 256 megabytes inp ...

  4. Codeforces 124A - The number of positions

    题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't ...

  5. CodeForces - 140A New Year Table (几何题)当时没想出来-----补题

    A. New Year Table time limit per test2 seconds memory limit per test256 megabytes inputstandard inpu ...

  6. codeforces Soldier and Number Game(dp+素数筛选)

    D. Soldier and Number Game time limit per test3 seconds memory limit per test256 megabytes inputstan ...

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

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

  8. Codeforces 448 D. Multiplication Table 二分

    题目链接:D. Multiplication Table 题意: 给出N×M的乘法矩阵要你求在这个惩罚矩阵中第k个小的元素(1 ≤ n, m ≤ 5·10^5; 1 ≤ k ≤ n·m). 题解: n ...

  9. Codeforces 980E The Number Games 贪心 倍增表

    原文链接https://www.cnblogs.com/zhouzhendong/p/9074226.html 题目传送门 - Codeforces 980E 题意 $\rm Codeforces$ ...

随机推荐

  1. MSCKF_VIO:MSCKF的双目版本

    论文:MSCKF的双目版本 Robust Stereo Visual Inertial Odometry for Fast Autonomous Flight 下载地址:点击 源码地址:https:/ ...

  2. IntelliJ IDEA 注册码激活

    IntelliJ IDEA 注册码激活 方法一:使用激活服务器激活方法 步骤 1.打开注册/激活窗口: 2.选择 License server: 3.填入上述其中一个网址(如:http://idea. ...

  3. 14.0-uC/OS-III挂起队列

    1.当任务等待信号量. mutex.事件标志组.消息队列时,该任务会被放入挂起队列. 挂起队列是一个OS_PEND_LIST类型的数据结构,它包含了三部分内容. .NbrEntries 挂起队列中有几 ...

  4. 5、Flutter 实现 ViewPager、bottomNavigationBar 界面切换

    1.前言 首先我们想一下,如果在 Android 中实现 布局切换,通常的思路是: 做一个 viewpager 一组 Fragment 每个 Fragment 绑定一个 xml 最后填充至 viewp ...

  5. vs添加github代码库

    1.安装git for windows 2.在vs中工具->扩展和更新,安装github extension 3.在项目中右键,添加源码到git,之后配置git,然后选择同步或者commit即可

  6. python 关于 input

    name = input("请输入你的姓名:") print(name) 解释:input表示输入,当你输入一个名字的时候, 它打印出来的东西,也就是你输入的东西, 结果: 请输入 ...

  7. PowerBI更新 - 解决方案架构 - PowerBI Solution Architecture(一图胜万字!)

    2019/04更新 参见这里 今天发福利啦!发福利啦!发福利啦! 企业的各种数据整合到PowerBI显示,浏览器,移动端显示关键指标. 一个很好的PowerBI解决方案的图!一图胜万字!你所需要知道的 ...

  8. Python openpyxl、pandas操作Excel方法简介与具体实例

    本篇重点讲解windows系统下 Python3.5中第三方excel操作库-openpyxl: 其实Python第三方库有很多可以操作Excel,如:xlrd,xlwt,xlwings甚至注明的数据 ...

  9. MySQL AUTO_INCREMENT 学习总结

    之前有碰到过开发同事指出一张InnoDB表的自增列 AUTO_INCREMENT 值莫明的变大,由于这张表是通过mysqldump导出导入的. 问题排查: 1.首先,查看表表义的sql部分的 auto ...

  10. 《linux就该这么学》第七节课:文件的各种权限以及linux分区命名规则

    笔记 (借鉴请改动) 5.3:文件特殊权限 SUID  临时拥有文件所有者的权限(基本上只是执行权限) SGID  临时拥有文件所有组的权限,在目录中创建文件自动继承该目录的用户组. SBIT  粘滞 ...