Discription:
There is an old country and the king fell in love with a devil. The devil always ask the king to do some crazy things. Although the king used to be wise and beloved by his people. Now he is just like a boy in love and can’t refuse any request from the devil. Also, this devil is looking like a very cute Loli.

Something bad actually happen. The devil makes this kingdom's people infected by a disease called lolicon. Lolicon will take away people's life in silence.

Although z*p is died, his friend, y*wan is not a lolicon. Y*wan is the only one in the country who is immune of lolicon, because he like the adult one so much.

As this country is going to hell, y*wan want to save this country from lolicon, so he starts his journey.

You heard about it and want to help y*wan, but y*wan questioned your IQ, and give you a question, so you should solve it to prove your IQ is high enough.

The problem is about counting. How many undirected graphs satisfied the following constraints?

1. This graph is a complete graph of size n. 
2. Every edge has integer cost from 1 to L. 
3. The cost of the shortest path from 1 to n is k.

Can you solve it?

output the answer modulo 10^9+7 

Input

The first line contains an integer T, denoting the number of the test cases.

For each test case, the first line contains 3 integers n,k,L.

T<=5 n,k<=12,L<=10^9.

Output

For each test case, output the answer in one line.

Sample Input

2
3 3 3
4 4 4

Sample Output

8
668 陈立杰大神出的题,想了想又写了写2h就过去了orz
题目大意就是给出n,k,L ,问有多少n个点的带标号的完全无向图,
满足1-n的最短路长度为k,且每条边的权值都>=1且<=L 。 (要不是上午ZHW点拨了几下我估计一晚上都做不出来hhh) 首先不能枚举最短路的构成,这样显然会挂掉,因为1-n可能会有很多条最短的路径; 然后考虑一下枚举每一个dis[i],代表1号节点到i号节点的最短路长度。
假设我们不用管枚举dis的时间花费,先关注一下如果dis都确定了的话如何更新答案。
先把dis从小到大排序,之后从后面的点向前面的每个节点连边(这样才能是完全图嘛。。)。
边权显然不是任意的,可以发现的是如果1到i(代表最短路长度从小到大排序后第i小点)
的最短路长度为dis[i]的话,必须满足:
1.对于所有的dis[j]<dis[i],
使得dis[j]+val(j,i)>=dis[i]
2.存在dis[j]<dis[i],
使得dis[j]+val(j,i)==dis[i]
满足上两个条件的方案数不难求,一个容斥就ojbk了。
然后再考虑dis[j]==dis[i]的点j,发现边权是多少都无所谓,所以都×L就行了。 但是可能会有点的dis>k,这可怎么办呢?
这样就设dis[i]==k(这里i!=n)的意思为1到i的最短路长度>=k,
那么我们统计这类节点的方案数就不用容斥减去了,直接乘上满足条件1的方案数就行了。 但是搜索出每个dis[i]的值是会TLE的,需要考虑一种更加高效的方法。 其实我们不必知道每个dis是多少,只需要知道对于1<=x<=k的每个x,dis[i]==x的i有多少个就行了。
这样我们改变搜索对象(实验证明这样搜索能到达的状态最多有10^5种,再乘上n^2的更新答案时间根本不虚),
中间计算的时候乘上组合数就行了(相当于算等于x的dis[i]分别对应原图中的哪些节点)
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<map>
#include<cstring>
#define ll long long
#define ha 1000000007
using namespace std;
ll n,k,L,T,ans;
ll C[][],jc[];
ll num[],cnt=;
ll ci[][]; inline void init(){
C[][]=jc[]=;
for(int i=;i<=;i++){
C[i][]=,jc[i]=jc[i-]*(ll)i%ha;
for(int j=;j<=i;j++){
C[i][j]=C[i-][j-]+C[i-][j];
if(C[i][j]>=ha) C[i][j]-=ha;
}
}
} inline ll calc(){
ll an=,rk1,rk2,fin=num[k];
num[k]=;
//先算num<k和num==k中的n的情况。
for(int i=;i<=k;i++) if(num[i]){
rk1=rk2=;
for(int j=;j<i;j++) if(num[j]){
rk1=rk1*ci[i-j-][num[j]];
rk2=rk2*ci[i-j][num[j]];
if(rk1>=ha) rk1-=rk1/ha*ha;
if(rk2>=ha) rk2-=rk2/ha*ha;
} rk1+=ha-rk2;
if(rk1>=ha) rk1-=ha; for(int j=;j<=num[i];j++){
an=an*rk1;
rk1=rk1*L;
if(an>=ha) an-=an/ha*ha;
if(rk1>=ha) rk1-=rk1/ha*ha;
}
} //再求num==k的其他点的方案数
num[k]=fin-;
if(num[k]){
rk1=;
for(int i=;i<k;i++) if(num[i]){
rk1=rk1*ci[k-i-][num[i]];
if(rk1>=ha) rk1-=rk1/ha*ha;
} for(int j=;j<=num[k];j++){
rk1=rk1*L;
if(rk1>=ha) rk1-=rk1/ha*ha;
an=an*rk1;
if(an>=ha) an-=an/ha*ha;
}
} return an;
} void dfs(int tmp,int lef,ll alr){
if(tmp==k-){
num[k]=lef+;
ans+=alr*calc()%ha;
if(ans>=ha) ans-=ha;
return;
} for(int u=;u<=lef;u++){
ll to=alr*C[lef][u]%ha;
num[tmp+]=u;
dfs(tmp+,lef-u,to);
}
} inline void solve(){
dfs(,n,);
} int main(){
init();
scanf("%lld",&T);
while(T--){
ans=; memset(num,,sizeof(num));
memset(ci,,sizeof(ci)); scanf("%lld%lld%lld",&n,&k,&L);
if(L<k){
puts("");
continue;
} for(int i=;i<=k;i++){
ci[i][]=;
for(int j=;j<=n;j++) ci[i][j]=ci[i][j-]*(L-i+ha)%ha;
} n-=,num[]=num[k]=,solve();
printf("%lld\n",ans);
} return ;
}


												

HDOJ 4903 The only survival的更多相关文章

  1. hdu 4903 The only survival

    The only survival http://acm.hdu.edu.cn/showproblem.php?pid=4903 Time Limit: 40000/20000 MS (Java/Ot ...

  2. HDU.4903.The only survival(组合 计数)

    题目链接 惊了 \(Description\) 给定\(n,k,L\),表示,有一张\(n\)个点的无向完全图,每条边的边权在\([1,L]\)之间.求有多少张无向完全图满足,\(1\)到\(n\)的 ...

  3. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  5. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  6. HDOJ 1004 Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  7. hdoj 1385Minimum Transport Cost

    卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛 ...

  8. (转)A Survival Guide to a PhD

    Andrej Karpathy blog About Hacker's guide to Neural Networks A Survival Guide to a PhD Sep 7, 2016 T ...

  9. HDOJ(2056)&HDOJ(1086)

    Rectangles    HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...

随机推荐

  1. getActionBar为null的解决以及ActionBar的Back键

    http://blog.csdn.net/lincyang/article/details/46286895

  2. linux+GraphicsMagick 安装

    转摘自:http://blog.csdn.net/fhqsse220/article/details/12995763 GraphicsMagick 安装 下载软件:download:ftp://ft ...

  3. es6+最佳入门实践(13)

    13.模块化 13.1.什么是模块化 模块化是一种处理复杂系统分解为更好的可管理模块的方式.通俗的讲就是把一个复杂的功能拆分成多个小功能,并且以一种良好的机制管理起来,这样就可以认为是模块化.就像作家 ...

  4. 【BZOJ3132】上帝造题的七分钟 [树状数组]

    上帝造题的七分钟 Time Limit: 20 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description “第一分钟,X说,要有矩阵 ...

  5. 【BZOJ2002】【HNOI2010】弹飞绵羊 [分块]

    弹飞绵羊 Time Limit: 10 Sec  Memory Limit: 259 MB[Submit][Status][Discuss] Description 某天,Lostmonkey发明了一 ...

  6. sublime text 2学习(二):创建可复用的代码片段

    对于前端工程师来讲,写一个html页面的基本结构是体力活,每次去拷贝一个也麻烦,sublime text 2 提供了一个很好的复用代码片段.下面介绍一下创建一个html5的代码片段的过程. 在菜单上点 ...

  7. 命令行工具PathMarker

    一直使用Guake 终端,Guake提供的其中一个功能是快速打开. 大概的意思就是,显示在终端上的数据会经过匹配,如果符合一定的规则,则可以按住ctrl,使用鼠标单击以触发指定操作. 比如对于一个文件 ...

  8. 【LA3461】Leonardo的笔记本

    白书例题. #include<bits/stdc++.h> using namespace std; ],vis[],cnt[]; inline int read(){ ,x=;char ...

  9. jQuery-niceScroll使用中父子div都存在滚动条导致错位的问题

    1.做项目时因为客户要求改变了项目的整体样式,所以导致浏览器自带的滚动条样式与项目的样式风格格格不入,所以要使用一个滚动条插件来替换浏览器自带的滚动条,我在网上搜了下,发现niceScroll这个滚动 ...

  10. JSP 基础之 JSTL <c:if>用法

    <c:if>还有另外两个属性var和scope.当我们执行<c:if>的时候,可以将这次判断后的结果存放到属性var里:scope则是设定var的属性范围.哪些情况才会用到va ...