题目链接: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. 洛谷试炼场 - 关卡2-1 - 简单的模拟 - (Done)

    最近这段时间感冒外加一些乱七八糟的事情,导致脑子严重僵化……只好刷刷基础(水)题巩固巩固基础(混混题数). 目录 P1003 铺地毯 P1067 多项式输出 P1540 机器翻译 P1056 排座椅 ...

  2. CentOS7.6 安装Docker

    删除已安装的Docker # Uninstall installed docker sudo yum remove docker \ docker-client \ docker-client-lat ...

  3. ConnectionAbortedError: [WinError 10053] 你的主机中的软件中止了一个已建立的连接

    Traceback (most recent call last): File "C:\Users\Administrator\AppData\Local\Programs\Python\P ...

  4. 详解FPGA中的建立时间与保持时间

    概念对于一个数字系统而言,建立时间和保持时间可以说是基础中的基础,这两个概念就像是数字电路的地基,整个系统的稳定性绝大部分都取决于是否满足建立时间和保持时间.但是对于绝大部分包括我在内的初学者来说,建 ...

  5. docker容器的操作

    容器操作 1.查看本地容器 docker ps -a # 查看所有容器 docker ps # 查看所有正在运行的容器 2.容器的创建与启动 方法一:两步完成(强烈推荐方法)(1)创建 docker ...

  6. python基础之 异常处理和logging模块

    1.异常处理 l = ['apple','admin','kobe'] for id,item in enumerate(l,1): print(id,item) try: choose_id = i ...

  7. 【C】NO.85.EBook.10.C.1.001-【C primer plus】-

    1.0.0 Summary Tittle:[C]NO.85.EBook.10.C.1.001-[C primer plus]- Style:C Series:C Since:2018-02-06 En ...

  8. 6种原型设计工具大比对! Axure,Invision, 墨刀……哪款适合你?

    每一年的毕业季都是找工作高峰时期,产品经理.UI设计师这些岗位都会接触到原型设计工具.选择原型设计工具最重要的一点:适合自己的才是最好的! 下文将对目前超火的原型工具进行大对比,快来看看那一款于你而言 ...

  9. MySQL Backup mysqldump 常用选项与主要用法

    The mysqldump client utility performs logical backups, producing a set of SQL statements that can be ...

  10. JavaBean-EL-JSTL-MVC

    JavaBean规范 类必须使用public修饰     必须保证有公共无参数构造器.  (一般就是可以通过反射轻松的创建对象)  包含了属性的操作(给属性赋值,获取属性值). JavaBean中的成 ...