[Codeforces VK Cup 2016
来源:互联网 发布:数据分析法 编辑:程序博客网 时间:2024/04/26 23:25
首先暴力上矩阵树定理加高斯消元是要T的
因为k+1~n的每个点只会向比它小的点连边,那么倒消元,每个方程就只要消最多k个元,这样复杂度就很小了……
不过这种做法被Manchery叉掉了……所以只能加个骗分的标签
#include <cstdio>#include <iostream>#include <algorithm>#include <map>#define N 10010#define P 1000000007using namespace std;typedef map<int,int>::iterator itr;int n,k;int d[N];map<int,int> A[N];inline char nc(){ static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}inline void rea(int &x){ char c=nc(); x=0; for(;c>'9'||c<'0';c=nc());for(;c>='0'&&c<='9';x=x*10+c-'0',c=nc());}inline int Pow(int x,int y){ int ret=1; for(;y;y>>=1,x=1ll*x*x%P) if(y&1) ret=1ll*ret*x%P; return ret;}inline int inv(int x){ return Pow(x,P-2);}inline void gauss(int x,int y){ int now=1ll*inv(A[x][x])*A[y][x]%P; for(itr i=A[x].begin();i!=A[x].end();i++) if(i->first<n) (A[y][i->first]+=P-1ll*now*A[x][i->first]%P)%=P; int cnt=0; for(itr i=A[y].begin();i!=A[y].end();i++) if(i->first<n&&!(i->second)) d[++cnt]=i->first; for(int i=1;i<=cnt;i++) A[y].erase(A[y].find(d[i]));}inline int det(){ for(int i=1;i<n;i++) for(itr j=A[i].begin();j!=A[i].end();j++) if(j->first!=i&&j->first<n) gauss(i,j->first); int ret=1; for(int i=1;i<n;i++) ret=1ll*ret*A[i][i]%P; return ret;}int main(){ rea(n); rea(k); for(int i=n-k;i;i--) for(int j=1;j<=k;j++){ int x; rea(x); x=n-x+1; A[i][x]=A[x][i]=P-1; A[i][i]++; A[x][x]++; } for(int i=n-k+1;i<=n;i++) for(int j=i+1;j<=n;j++) A[i][j]=A[j][i]=P-1,A[i][i]++,A[j][j]++; return printf("%d\n",det()),0;}
0 0
- [Codeforces VK Cup 2016
- Codeforces VK Cup 2015
- Codeforces VK Cup 2017
- Codeforces VK Cup 2016 - Round 1 (Div. 2 Edition)
- 【codeforces VK Cup Round 1】BDE题解
- [杂题] Codeforces 772D VK Cup 2017
- [几何] Codeforces 772B VK Cup 2017
- 51Nod 1524 | Codeforces VK Cup 2015
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 1 Edition)
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) A B C D 模拟
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) easy(上)
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) A B C D 构造
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) ABCD
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D. Bear and Two Paths
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)
- Codeforces Round #348 (VK Cup 2016 Round 2) E F (2-sat. 待补)
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 1 Edition)
- Discuz!开发之电脑访问手机版网址自动跳转到电脑版网址
- VTK:测量类widget总结
- 使用Android Studio遇到的坑
- 算法训练 JAM计数法
- 【zzulioj 2134: 维克兹的进制转换】+ dp
- [Codeforces VK Cup 2016
- POJ 1082 博弈推规律
- 新品活动,1000件套装,限量免.费赠送CHANEL礼盒三件套(邂逅香水+coco香水+口红)Z
- STL库之Map结构的使用
- Java动态代理之CGLIB
- 【Ubuntu】手动建立快捷方式
- Windbg 实战常用命令--会不断更新
- CC2640 自学mark
- 大数据数据分析POM.XML