The only survival

Time Limit: 40000/20000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 255    Accepted Submission(s): 120

Problem Description
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
Author
WJMZBMR
Source
题目大意:有一张n个点的无向完全图,第i个点的编号是i,每条边的边权在1到L之间的正整数,问存在多少个图使得1到n的最短路是k。
分析:神题!
   一个暴力的做法是枚举所有点到1号点的最短路,记作d[i],如果d[i] == d[j],那么i,j之间的边的权值可以任意选,否则边权不能小于|di-dj|,且必然有一条边使得di + dist[i][j] = dj.只是枚举的复杂度高达13^12,承受不了.
   其实我们不需要考虑每个点的最短路具体是什么,只需要考虑数量就可以了.计数题的一个转换思路.那么在dfs的时候枚举每个最短路对应的点有多少个就可以了.然后就是极其琐碎的组合数运算.
   需要注意的是起点和终点的最短路都已经确定了.选取i个点的组合数要排除这两个点. 同时可能会有大于k的最短路出现,统统放到k+1处理.关于具体的组合数的运算我写在了代码里:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; typedef long long ll;
const int mod = 1e9+;
int T;
ll n,k,l,cnt[],ans,c[][]; void init()
{
c[][] = ;
for (int i = ; i <= ; i++)
{
c[i][] = ;
for (int j = ; j <= ; j++)
c[i][j] = (c[i - ][j] + c[i - ][j - ]) % mod;
}
} ll qpow(ll a,ll b)
{
ll res = ;
while (b)
{
if (b & )
res = (res * a) % mod;
a = (a * a) % mod;
b >>= ;
}
return res;
} ll solve(ll x)
{
if (!cnt[x])
return ;
ll x1 = ,x2 = ;
for (int i = ; i < x; i++)
{
if (!cnt[i])
continue;
if (x - i > l) //方案不合法,最短路会被更新
return ;
x1 = (x1 * qpow(l - (x - i) + ,cnt[i])) % mod; //x1是所有能选的方案
x2 = (x2 * qpow(l - (x - i),cnt[i])) % mod; //x2是所有不合法的方案
}
if (x == k + ) //如果最短路大于k了,那么所有能选的方案都是合法的,因为只是把它们归到k+1这一类,最短路并不一定要等于k+1
return qpow(x1,cnt[x]) % mod;
x1 -= x2;
if (x1 < )
x1 += mod;
return qpow(x1,cnt[x]) % mod; //之前的方案数都是对于所有的i,1个x来计算的.
} void dfs(ll dep,ll fangan,ll tot) //tot传的是1
{
if (dep == k)
{
for (int i = ; i + tot <= n; i++)
{
ll temp = fangan * c[n - tot - ][i - ] % mod; //剩下的点中选i-1个最短路为k的点,第i个点为终点,不考虑.
temp = (temp * qpow(l,c[i][])) % mod; //这两行就是两两最短路相等的算方案数
temp = (temp * qpow(l,c[n - tot - i][])) % mod;
cnt[k] = i;
cnt[k + ] = n - tot - i;
temp = (temp * solve(k)) % mod;
temp = (temp * solve(k + )) % mod; //最短路大于k的都放到k+1处计算.
ans = (ans + temp) % mod;
}
return;
}
for (int i = ; i + tot < n; i++)
{
cnt[dep] = i;
ll temp = fangan * qpow(l,c[i][]) % mod; //上面说的di == dj的情况,边权随便取
temp = (temp * c[n - tot - ][i]) % mod; //能选的点中选i个点的方案数
temp = (temp * solve(dep)) % mod;
dfs(dep + ,temp,i + tot);
}
} int main()
{
scanf("%d",&T);
init();
while (T--)
{
scanf("%lld%lld%lld",&n,&k,&l);
memset(cnt,,sizeof(cnt));
cnt[] = ; //起点被确定了
ans = ;
dfs(,,);
printf("%lld\n",ans);
} return ;
}

Hdu4903 The only survival的更多相关文章

  1. (转)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 ...

  2. survival analysis 生存分析与R 语言示例 入门篇

    原创博客,未经允许,不得转载. 生存分析,survival analysis,顾名思义是用来研究个体的存活概率与时间的关系.例如研究病人感染了病毒后,多长时间会死亡:工作的机器多长时间会发生崩溃等. ...

  3. (转) A Survival Guide to a PhD

    A Survival Guide to a PhD Sep 7, 2016 This guide is patterned after my “Doing well in your courses”, ...

  4. JSBinding + SharpKit / 实战:转换 Survival Shooter

    从 asset store 下载 Survival Shooter (商店里有2个版本,一种是给Unity5用的,一个是给Unity4.6用的,我们这个实验用的是后者,版本是2.2.如果) 1 删除多 ...

  5. A Mathematician‘s Survival Guide Graduate School and Early Career Development

    推荐大家一本书尤其是即将读研究生或者研一研二的学生:                                                     A Mathematician‘s  Su ...

  6. 生存模型(Survival Model)介绍

    https://www.cnblogs.com/BinbinChen/p/3416972.html 生存分析,维基上的解释是: 生存分析(Survival analysis)是指根据试验或调查得到的数 ...

  7. [LightOJ 1265] Island of Survival

    Island of Survival You are in a reality show, and the show is way too real that they threw into an i ...

  8. Survival Analysis

    code{white-space: pre;} Survival Analysis Zhu Lin 2017-3-18 What is Survival Analysis Survival analy ...

  9. Spark2 生存分析Survival regression

    在spark.ml中,实现了加速失效时间(AFT)模型,这是一个用于检查数据的参数生存回归模型. 它描述了生存时间对数的模型,因此它通常被称为生存分析的对数线性模型. 不同于为相同目的设计的比例风险模 ...

随机推荐

  1. iOS学习笔记(2)— UIView用户事件响应

    UIView除了负责展示内容给用户外还负责响应用户事件.本章主要介绍UIView用户交互相关的属性和方法. 1.交互相关的属性 userInteractionEnabled 默认是YES ,如果设置为 ...

  2. JSP中page,request,session,application四个域对象区别

    page page指当前页面.只在一个jsp页面里有效 . page里的变量没法从index.jsp传递到test.jsp,只要页面跳转了,它们就不见了. pageContext 如果把变量放到pag ...

  3. 20 Organizing Go code 组织go代码

    Organizing Go code 16 August 2012 Introduction Go code is organized differently to that of other lan ...

  4. 栈应用之 后缀表达式计算 (python 版)

    栈应用之 后缀表达式计算 (python 版) 后缀表达式特别适合计算机处理 1.  中缀表达式.前缀表达式.后缀表达式区别  中缀表达式:(3 - 5) * (6 + 17 * 4) / 3 17 ...

  5. PHP获得用户的真实IP地址

    <?php /** * 获得用户的真实IP地址 * * @access public * @return string */ function real_ip() { static $reali ...

  6. python基础--json,pickle和shelve模块

    一.JSON &pickle 用于序列化的两个模块 json,用于字符串 和 python数据类型间进行转换  字符串必须是双引号,不能是单引号 pickle,用于python特有的类型 和 ...

  7. Linux学习笔记:wc查看文件字节数、字数、行数

    Linux系统中的wc(Word Count)命令可以统计指定文件中的字节数.字数.行数,并将统计结果显示输出. 若不指定文件名称,或是所给予的文件名为“-”,则wc指令会从标准输入设备读取数据. 语 ...

  8. » Working Around JNI UTF-8 Strings Deprogramming

    private static native void printString(String text); ... void examplePrintString() { String str = &q ...

  9. 基于CommonsChunkPlugin,webpack打包优化

    前段时间一直在基于webpack进行前端资源包的瘦身.在项目中基于路由进行代码分离,http://www.cnblogs.com/legu/p/7251562.html.但是打包的文件还是很大,特别是 ...

  10. <未来世界的幸存者> 读后感(现实篇和职业篇)【原创】

    摘要: 前几天有幸看到阮老师的 <未来世界的幸存者)>,花了几晚的时间阅读完毕,内心受到了很大的触动,现在将感觉不错的地方记录下. 职业篇 1. 为什么雇佣制度对工人不利? 雇佣制度是一种 ...