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$ ...
随机推荐
- php验证18位身份证,准到必须输入正确的身份证号,
/** * 验证18位身份证(计算方式在百度百科有) * @param string $id 身份证 * return boolean */ function check_identity($id=' ...
- select 标签判断value值相同 就selected高亮
我写的是里面嵌套php标签 <select name="bq_id[]" multiple="multiple"> <volist name= ...
- vue2.0 源码解读(一)
又看完一遍中文社区的教程接下来开始做vue2.0的源码解读了! 注:解读源码时一定要配合vue2.0的生命周期和API文档一起看 vue2.0的生命周期分为4主要个过程 create. 创建---实例 ...
- Android开发入门经典【申明:来源于网络】
Android开发入门经典[申明:来源于网络] 地址:http://wenku.baidu.com/view/6e7634050740be1e650e9a7b.html?re=view
- Codeforces 483 - A/B/C/D/E - (Done)
题目链接:http://codeforces.com/contest/483 A - Counterexample - [简单构造题] Your friend has recently learned ...
- awt
public class MouseTest extends Frame{ private static final long serialVersionUID = 54376853365952763 ...
- Mycat了解下
首先说下,因为本身不怎么推荐中间件,所以我对这东西也只是了解,业内mycat用的最好的应该顺风算一个,但是他们是做过二次开发的,咱菜鸡比不了,据说最近出来一个叫cetus的还不错,有空可以关注下 Ⅰ. ...
- jsp一些使用技巧
1.web.xml中配置error页面 一.<error-page> <error-code>500</error-code> <location>50 ...
- Vue滑动删除与修改
Vu+element实现 <template> <div class=""> <div class="slider"> &l ...
- HDU 1160
FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take ...