HDU4903The only survival(clj计数问题ppt)
2015-10-08 23:30
162 查看
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4903
题意:问有多少种无向完全图满足1-n最短路径为k且每条边都在[1,L];
L<10910^9,n,k<=12;
分析:先想暴力怎么计算答案,一种方法是枚举1到每个点的最短路长度,然后图的种数就可以计算了;仔细思考发现我们只关心d[i]=x的点个数即可,由于我们只关心d[i]
题意:问有多少种无向完全图满足1-n最短路径为k且每条边都在[1,L];
L<10910^9,n,k<=12;
分析:先想暴力怎么计算答案,一种方法是枚举1到每个点的最短路长度,然后图的种数就可以计算了;仔细思考发现我们只关心d[i]=x的点个数即可,由于我们只关心d[i]
#include<bits/stdc++.h> using namespace std; typedef long long Int; const int M=1e9+7; int c[20][20]; void cal() { for(int i=0;i<13;i++)c[i][0]=1; for(int i=1;i<13;i++) for(int j=1;j<=i;j++) c[i][j]=(c[i-1][j]+c[i-1][j-1])%M; } int cnt[14]; int n,k,L,ans; int powmod(int x,int y){int ret=1;while(y){if(y&1)ret=ret*(Int)x%M;y>>=1;x=x*(Int)x%M;}return ret;} inline void up(int &x,int y){x+=y;if(x>=M)x-=M;} int solve(int x) { if(!cnt[x])return 1; int t1=1,t2=1; for(int j=0;j<x;j++) { if(!cnt[j])continue; if(x-j>L)return 0; t1=t1*(Int)powmod(L-(x-j)+1,cnt[j])%M; t2=t2*(Int)powmod(L-(x-j),cnt[j])%M; } if(x==k+1)return powmod(t1,cnt[x]); t1-=t2;if(t1<0)t1+=M; t1=powmod(t1,cnt[x]); return t1; } void dfs(int cur,int rep,int tot) { if(cur==k) { for(int i=1;i+tot<=n;i++)//i个人选k { int tprep=rep*(Int)c[n-tot-1][i-1]%M; tprep=tprep*(Int)powmod(L,c[i][2])%M*(Int)powmod(L,c[n-tot-i][2])%M; cnt[k]=i; cnt[k+1]=n-tot-i; tprep=tprep*(Int)solve(k)%M*(Int)solve(k+1)%M; up(ans,tprep); } return; } for(int i=0;i+tot<n;i++) { cnt[cur]=i; int tprep=rep*(Int)powmod(L,c[i][2])%M; tprep=tprep*(Int)c[n-tot-1][i]%M; tprep=tprep*(Int)solve(cur)%M; dfs(cur+1,tprep,tot+i); } } int main() { cal(); int _;scanf("%d",&_); while(_--) { scanf("%d%d%d",&n,&k,&L); memset(cnt,0,sizeof(cnt)); cnt[0]=1; ans=0; dfs(1,1,1); printf("%d\n",ans); } }
相关文章推荐
- Python的哲学
- AugularJS特性
- php——composer 1、安装使用
- 黑马程序员-------封装 继承 多态 的一些概念
- 高手对了网站搜索可用性的一些总结
- 包的应用
- 目标检测——CodeBook背景建模(原理+Opencv实现代码)
- BestCoder Round #56 (div.2) HDU5463 Clarke and minecraft
- 浏览器刷新缓存机制
- HDU 3746 Cyclic Nacklace
- shop++源代码
- 使用java代码生成图片验证码
- HashSet:底层数据结构是哈希表
- 黑马程序员--C语言之数组的定义以及使用
- Object类
- 几年的Git使用技巧总结
- Linux 执行数学运算
- android布局改变动画
- poj1113 凸包入门题
- MySQL学习历程——数据库操作命令