题目链接: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. MySQL建表、插入语句等

    不定时更新MySQL的一些基础语句以及出现过的问题 5.10 建表语句 CREATE TABLE `policy_landvalue` ( `id` ) NOT NULL AUTO_INCREMENT ...

  2. ubuntu系统上如何添加新的根证书

    如果自己部署了一个CA系统,或者使用openssl生成了一个自签名的证书,如何让ubuntu系统信任这些证书呢 添加证书: 首先,复制pem格式的根证书,重命名为 .crt格式 然后,执行下边的命令 ...

  3. [qemu][kvm] 在kvm嵌套kvm的虚拟机里启动kvm加速

    常规情况下,如果在kvm的虚拟机里,又想使用kvm的虚拟机,会报如下的错误信息: [root@host0 nlb]# Could not access KVM kernel module: No su ...

  4. 1.认识Wireshark的主窗口界面(转)

    原文地址:https://www.ichunqiu.com/vm/51411/1 (1)首先了解一下这款软件主窗口界面中每个部分的功能.Wireshark主窗口界面如下图所示: 上图中每部分的含义如下 ...

  5. GreenDao开源ORM框架浅析

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u011133213/article/details/37738943 Android程序开发中,避免 ...

  6. 020-并发编程-java.util.concurrent之-jdk6/7/8中ConcurrentHashMap、HashMap分析

    一.概述 哈希表(hash table)也叫散列表,是一种非常重要的数据结构,应用场景及其丰富,许多缓存技术(比如memcached)的核心其实就是在内存中维护一张大的哈希表. 是根据关键码值(Key ...

  7. python框架之Django(14)-rest_framework模块

    APIView django原生View post请求 from django.shortcuts import render, HttpResponse from django import vie ...

  8. python框架之Flask(1)-Flask初使用

    Flask是一个基于 Python 开发并且依赖 jinja2 模板和 Werkzeug WSGI 服务的一个微型框架,对于 Werkzeug 本质是 Socket 服务端,其用于接收 http 请求 ...

  9. spring-boot 速成(2) devtools之热部署及LiveReload

    JRebel热部署插件相信很多人都知道,但是这是一款商业插件,spring-boot框架也提供了类似的功能,即:devtools,关键是免费的! 使用方法如下: 一.添加 devtools依赖 dep ...

  10. mysql的一些指令

    说起来mysql,mysql其实是特别简单操作的数据库.它有一下几方面的特点,亦或者是说优点,1,支持多语言:2.移植性比较好:3,我觉得最重要的一点就是它是开源的,因为开源,所以使用广泛,4.效率比 ...