Hdu4903 The only survival
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
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
For each test case, the first line contains 3 integers n,k,L.
T<=5 n,k<=12,L<=10^9.
3 3 3
4 4 4
668
#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的更多相关文章
- (转)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 ...
- survival analysis 生存分析与R 语言示例 入门篇
原创博客,未经允许,不得转载. 生存分析,survival analysis,顾名思义是用来研究个体的存活概率与时间的关系.例如研究病人感染了病毒后,多长时间会死亡:工作的机器多长时间会发生崩溃等. ...
- (转) 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”, ...
- JSBinding + SharpKit / 实战:转换 Survival Shooter
从 asset store 下载 Survival Shooter (商店里有2个版本,一种是给Unity5用的,一个是给Unity4.6用的,我们这个实验用的是后者,版本是2.2.如果) 1 删除多 ...
- A Mathematician‘s Survival Guide Graduate School and Early Career Development
推荐大家一本书尤其是即将读研究生或者研一研二的学生: A Mathematician‘s Su ...
- 生存模型(Survival Model)介绍
https://www.cnblogs.com/BinbinChen/p/3416972.html 生存分析,维基上的解释是: 生存分析(Survival analysis)是指根据试验或调查得到的数 ...
- [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 ...
- Survival Analysis
code{white-space: pre;} Survival Analysis Zhu Lin 2017-3-18 What is Survival Analysis Survival analy ...
- Spark2 生存分析Survival regression
在spark.ml中,实现了加速失效时间(AFT)模型,这是一个用于检查数据的参数生存回归模型. 它描述了生存时间对数的模型,因此它通常被称为生存分析的对数线性模型. 不同于为相同目的设计的比例风险模 ...
随机推荐
- 子查询优化--explain与profiling分析语句
今天想的利用explain与progiling分析下语句然后进行优化.本文重点是如何通过explain与profiling分析SQL执行过程与性能.进而明白索引的重要性. 表的关系如下所示: 原始的查 ...
- Java枚举类型的用法
JDK1.5引入了新的类型——枚举.在 Java 中它虽然算个“小”功能,却给我的开发带来了“大”方便. 1.用法一:常量 在JDK1.5 之前,我们定义常量都是: public static fia ...
- vi 编辑器使用技巧
1.由命令"vi --version"所显示的内容知vi的全局配置文件 2.显示行号 ,非编辑模式输入 : set nu 3.显示颜色 1)在文件中找到 "synta ...
- NIO编程中buffer对象的理解以及API的使用
概念讲解,转自https://www.cnblogs.com/lxzh/archive/2013/05/10/3071680.html ,将的非常好! Buffer 类是 java.nio 的构造基 ...
- ubuntu网络连接:Ifupdown(eth0)的连接不能修改或删除
今天其实遇到了三个问题,一个是ubuntu系统上的网络图标不见了,把网络图标弄出来以后有无法联网,联网成功却变成Ifupdown(eth0)的连接且不能修改或删除. 这里我只记录最后一个问题,前两个问 ...
- verilog中wire与reg类型的区别
每次写verilog代码时都会考虑把一个变量是设置为wire类型还是reg类型,因此把网上找到的一些关于这方面的资料整理了一下,方便以后查找. wire表示直通,即只要输入有变化,输出马上无条件地反映 ...
- 一、springcloud服务注册、发现、调用(consul/eureka)
1.Spring Cloud简介 Spring Cloud是一个基于Spring Boot实现的云应用开发工具,它为基于JVM的云应用开发中的配置管理.服务发现.断路器.智能路由.微代理.控制总线.全 ...
- GMM 模型需不需归一化问题
工作中遇到的问题:在GMM模型中添加一维scale比较大的特征,需不需要归一化 答案:不需要,推导如下:
- java基础35 双例集合Map及其常用方法
单例集合体系: ---------| collection 单例集合的根接口--------------| List 如果实现了list接口的集合类,具备的特点:有序,可重复 注:集合 ...
- eclipse各种报错
1.控制台报这个错是由于tomcat的session缓存的问题; org.apache.catalina.session.StandardManager doLoad 造成原因:上次未正确关闭tomc ...