CodeForces 51 E.Pentagon(组合数学)
来源:互联网 发布:取英文名字的软件 编辑:程序博客网 时间:2024/06/06 15:50
Description
给出一个
Input
第一行两整数
Output
输出五元环个数
Sample Input
5 5
1 2
2 3
3 4
4 5
5 1
Sample Output
1
Solution
假设一个五元环为
Code
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<queue>#include<map>#include<set>#include<ctime>using namespace std;typedef long long ll;typedef pair<int,int>P;const int INF=0x3f3f3f3f,maxn=705;ll A[maxn][maxn],B[maxn][maxn],C[maxn][maxn];int n,m,deg[maxn];void Mul(ll A[][maxn],ll B[][maxn],ll C[][maxn]){ for(int i=1;i<=n;i++) for(int j=1;j<=i;j++) { C[i][j]=0; for(int k=1;k<=n;k++)C[i][j]+=A[i][k]*B[k][j]; C[j][i]=C[i][j]; }}int main(){ while(~scanf("%d%d",&n,&m)) { for(int i=1;i<=n;i++) { deg[i]=0; for(int j=1;j<=n;j++)A[i][j]=0; } while(m--) { int u,v; scanf("%d%d",&u,&v); A[u][v]=A[v][u]=1; deg[u]++,deg[v]++; } Mul(A,A,B); Mul(A,B,C); ll ans=0; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) ans+=B[i][j]*C[i][j]; ans/=10; for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) if(A[i][j]) for(int k=j+1;k<=n;k++) if(A[i][k]&&A[j][k]) ans-=(deg[i]+deg[j]+deg[k]-3); printf("%I64d\n",ans); } return 0;}
阅读全文
0 0
- CodeForces 51 E.Pentagon(组合数学)
- [杂题 计数 图论] Codeforces 51E. Pentagon
- CF-51E - Pentagon(DP)
- Codeforces 689E Mike and Geometry Problem(组合数学)
- CodeForces 15 E.Triangles(组合数学+dp)
- CodeForces 40 E.Number Table(组合数学)
- Codeforces E. Qwerty78 Trip 【组合数学】
- codeforces 893E Counting Arrays (组合数学)
- codeforces 893E(组合数学&组合数取mod)
- CodeForces - 660E Different Subsets For All Tuples (组合数学&DP)好题
- CodeForces 451E Devu and Flowers(容斥原理+组合数学+状态压缩)
- codeforces 451E. Devu and Flowers (容斥原理+组合数学)
- CodeForces 660 E.Different Subsets For All Tuples(组合数学)
- CodeForces 711 E.ZS and The Birthday Paradox(组合数学)
- Educational Codeforces Round 33 (Rated for Div. 2) E. Counting Arrays(组合数学)
- Codeforces 560 E. Gerald and Giant Chess (dp,组合数学)
- CodeForces 520E. Pluses everywhere 字符串,组合数学
- Codeforces 660E Different Subsets For All Tuples【组合数学】
- python连载第11篇 if 语句
- coding pages 搭建静态博客
- SDUT 2116-数据结构实验之链表一:顺序建立链表
- 三行Python代码搞定人脸识别
- 数据结构实验之查找七:线性之哈希表
- CodeForces 51 E.Pentagon(组合数学)
- lucas 定理,组合数取模
- 第八章习题
- 对laravel框架中的Eloquent model的一点认识
- 验证码功能实现
- 计算机视觉如何入门
- Apache 使用ssl模块配置HTTPS
- vscode golang详细配置(持续更新)
- 激活world