codeforces736D. Permutations(线性代数)
题意
$m \leqslant 500000$,题目打错了
Sol
神仙题Orz
构造矩阵$B$,使得$B[b[i]][a[i]] = 1$
那么他的行列式的奇偶性也就对应了生成排列数列数量的奇偶性(定义)
删除一个位置相当于去掉对答案的贡献,也就是代数余子式的值
代数余子式可以由伴随矩阵求出$A^{*} = |A| A^{-1}$
这里只需要奇偶性,因此不需要求出实际行列式的值。
矩阵可以用bitset加速,可以过掉这个题
#include<cstdio>
#include<bitset>
#include<iostream>
using namespace std;
const int MAXN = ;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int N, M;
bitset<MAXN * + > b[MAXN];
int x[], y[];
int main() {
N = read(); M = read();
for(int i = ; i <= N; i++) b[i][i + N] = ;
for(int i = ; i <= M; i++) {
x[i] = read(), y[i] = read();
b[x[i]][y[i]] = ;
}
for(int i = , j; i <= N; i++) {
for(j = i; j <= N; j++) if(b[j][i]) {swap(b[i], b[j]); break;}
for(int k = ; k <= N; k++)
if(b[k][i] && (k != i)) b[k] ^= b[i];
}
for(int i = ; i <= N; i++, puts(""))
for(int j = ; j <= * N; j++)
cout << b[i][j] << " ";
return ;
}
/*
3 7
1 1
1 3
2 2
2 3
3 1
3 2
3 3 */
codeforces736D. Permutations(线性代数)的更多相关文章
- 【CF736D】Permutations 线性代数+高斯消元
[CF736D]Permutations 题意:有一个未知长度为n的排列和m个条件,第i个条件$(a_i,b_i)$表示第$a_i$个位置上的数可以为$b_i$.保证最终合法的排列的个数是奇数.现在有 ...
- 【线性代数】5-2:置换和余因子(Permutations and Cofactors)
title: [线性代数]5-2:置换和余因子(Permutations and Cofactors) categories: Mathematic Linear Algebra keywords: ...
- 线性代数导论 | Linear Algebra 课程
搞统计的线性代数和概率论必须精通,最好要能锻炼出直觉,再学机器学习才会事半功倍. 线性代数只推荐Prof. Gilbert Strang的MIT课程,有视频,有教材,有习题,有考试,一套学下来基本就入 ...
- Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations ...
- [LeetCode] Permutations II 全排列之二
Given a collection of numbers that might contain duplicates, return all possible unique permutations ...
- [LeetCode] Permutations 全排列
Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...
- POJ2369 Permutations(置换的周期)
链接:http://poj.org/problem?id=2369 Permutations Time Limit: 1000MS Memory Limit: 65536K Total Submi ...
- Permutations
Permutations Given a collection of distinct numbers, return all possible permutations. For example,[ ...
- 【leetcode】Permutations
题目描述: Given a collection of numbers, return all possible permutations. For example, [1,2,3] have the ...
随机推荐
- P2647 最大收益
题目描述 现在你面前有n个物品,编号分别为1,2,3,……,n.你可以在这当中任意选择任意多个物品.其中第i个物品有两个属性Wi和Ri,当你选择了第i个物品后,你就可以获得Wi的收益:但是,你选择该物 ...
- netty学习2
一.Netty分层设计 Netty 采用了比较典型的三层网络架构进行设计,逻辑架构图如下所示: #第一层,Reactor 通信调度层,它由一系列辅助类完成,包括 Reactor 线程 NioEvent ...
- AndroidStudio自动弹出Documentation
AndroidStudio自动弹出Documentation窗口 例如,在布局文件中添加 Button 标签 敲完 <Butotn 回车后就自动出现 Documentation窗口 那如何关闭自 ...
- CentOS 6.5远程连接工具x shell
安装X shell 在Window系统下远程连接Linux,x shell只是一种远程连接工具,类似工具还有CRT.VNC.putty. 以下是安装X shell的注意事项 此选项中,如不把——初始数 ...
- matlab白底换红底
白底换红底 局部阈值调整 边界高斯滤波 function demo global R global threshold global img global dstColor global rect g ...
- 单例模式-Lazy initialization holder class模式
这个模式综合使用了Java的类级内部类和多线程缺省同步锁的知识,很巧妙地同时实现了延迟加载和线程安全. 1.相应的基础知识 什么是类级内部类? 简单点说,类级内部类指的是,有static修饰的成员式内 ...
- app UI测试之UIAutomator
执行UIAutomator测试步骤 1.新建Java项目,导入android.jar和uiautomator.jar包,继承UiAutomatorTestCase 2.生成编译文件 android c ...
- JavaScript 对象字面量
JavaScript 对象字面量 JavaScript 对象字面量 在编程语言中,字面量是一种表示值的记法.例如,"Hello, World!" 在许多语言中都表示一个字符串字 ...
- 共相式GIS
今天看到SuperMap中一直提到共相式GIS,于是乎搜索一下……SuperMap的共相式怎么理解呢?iServer Java有咋理解呢??? 再谈共相式GIS和ArcObjects:ttp://ww ...
- git如何做个人构建
1 基本概念 1.1 Git:Git是一个版本控制的工具,类似于svn. 1.2 Gerrit:Gerrit是一个基于git的团队合作的工具,开发人员可以往上面提交代码, ...
