Codeforces 40 E. Number Table
题目链接: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的更多相关文章
- Codeforces 55D Beautiful Number
Codeforces 55D Beautiful Number a positive integer number is beautiful if and only if it is divisibl ...
- Codeforces 40E Number Table - 组合数学
题目传送门 传送门I 传送门II 题目大意 给定一个$n\times m$的网格,每个格子上要么填$1$,要么填$-1$,有$k$个位置上的数是已经填好的,其他位置都是空的.问有多少种填法使得任意一行 ...
- Codeforces 448 D. Multiplication Table
二分法判断答案 D. Multiplication Table time limit per test 1 second memory limit per test 256 megabytes inp ...
- Codeforces 124A - The number of positions
题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't ...
- CodeForces - 140A New Year Table (几何题)当时没想出来-----补题
A. New Year Table time limit per test2 seconds memory limit per test256 megabytes inputstandard inpu ...
- codeforces Soldier and Number Game(dp+素数筛选)
D. Soldier and Number Game time limit per test3 seconds memory limit per test256 megabytes inputstan ...
- Codeforces 55D Beautiful Number (数位统计)
把数位dp写成记忆化搜索的形式,方法很赞,代码量少了很多. 下面为转载内容: a positive integer number is beautiful if and only if it is ...
- Codeforces 448 D. Multiplication Table 二分
题目链接:D. Multiplication Table 题意: 给出N×M的乘法矩阵要你求在这个惩罚矩阵中第k个小的元素(1 ≤ n, m ≤ 5·10^5; 1 ≤ k ≤ n·m). 题解: n ...
- Codeforces 980E The Number Games 贪心 倍增表
原文链接https://www.cnblogs.com/zhouzhendong/p/9074226.html 题目传送门 - Codeforces 980E 题意 $\rm Codeforces$ ...
随机推荐
- Gym 101873I - Uberwatch - [DP]
题目链接:http://codeforces.com/gym/101873/problem/I 题意: 给出 $n(1 \le n \le 300000)$ 个单位时间,每个单位时间给出一个 $x_i ...
- Luogu 1086 - 花生采摘 - [简单模拟]
题目链接:https://www.luogu.org/problemnew/show/P1086 题目描述鲁宾逊先生有一只宠物猴,名叫多多.这天,他们两个正沿着乡间小路散步,突然发现路边的告示牌上贴着 ...
- python 中的__new__与__init__
在Python中的class中有两个方法__new__与__init__,有什么区别呢? class TestCls(): """docstring for TestCl ...
- 16.2-uC/OS-III同步 (事件标志组)
事件标志组 1.当任务要与多个事件同步时可以使用事件标志.若其中的任意一个事件发生时任务被就绪, 叫做逻辑或(OR).若所有的事件都发生时任务被就绪,叫做逻辑与( AND). 2.用户可以创建任意个事 ...
- AWK编程
1.awk的概述 文本处理工具,由于功能的强大,也可以当做是一种数据操作语言,非常适合结构化数据的处理和格式化报表的生成,awk可以进行样式装入.流控制.数学运算符.甚至于内置的变量和函数.它具备了一 ...
- [js]nodejs初探http/url/fs模块
难怪我没学会, 因为我的套路有问题. 错误点, 1,大而全 2,不注重思路 学习要领: 1, 小而精 2, 重思路(总结) nodejs特点: 1.node提供了js的运行环境, 一般将node运行在 ...
- Kaggle比赛:从何着手?
介绍 参加Kaggle比赛,我必须有哪些技能呢? 你有没有面对过这样的问题?最少在我大二的时候,我有过.过去我仅仅想象Kaggle比赛的困难度,我就感觉害怕.这种恐惧跟我怕水的感觉相似.怕水,让我无法 ...
- n皇后问题——关于斜线的编号
题目大意:在n*n的棋盘中,放置n个皇后(同一行.同一列.同一斜线,只有一个皇后) 这道题是一道非常经典的dfs模板题,同一行.同一列的判断不是很难,但同一斜线有一定的难度,下面给出关于斜线编号的解决 ...
- timer控件、三级联动、帐号激活权限设置
一.Timer控件 Timer实际就是一个线程控件. 属性:Enabled 是否被启用 Interval 多长时间执行一次控件中的代码 事件: Tick 事件中放要执行的代码. ...
- configparser配置文件处理
创建一个configparser格式的文档: import configparser config = configparser.ConfigParser()config["DEFAULT& ...