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)模型,这是一个用于检查数据的参数生存回归模型. 它描述了生存时间对数的模型,因此它通常被称为生存分析的对数线性模型. 不同于为相同目的设计的比例风险模 ...
随机推荐
- 「要买车网」免费获取汽车电商要买车网购车优惠券 - 持续更新(2016-03-12)www.fortunelab.cn
汽车电商要买车网简介 “要买车”(www.yaomaiche.com)网站是上海运图投资有限公司旗下网站,是首家真正打通交易闭环的汽车电商网站,由中国电子商务成功探索者——卜广齐于2014年10月在上 ...
- day04作业
1.for(初始化表达式:条件表达式:循环后的操作表达式){ 循环体: } class Test_Sum { public static void main(String[] args) { int ...
- 洛谷P1455搭配购买
传送门啦 这是强连通分量与背包的例题 需要注意的就是价值和价格两个数组不要打反了.. 另外 这是双向图!!! #include <iostream> #include <cstdio ...
- 前端程序员必知的30个Chrome扩展-[转载]
谷歌Chrome浏览器是网络上可用的最好浏览器之一,并且自2011年11月超越了Firefox浏览器之后,已经成为了互联网上占主导地位的浏览器.今天,HTML5中国与大家分享一些实用的谷歌Chrome ...
- Java与redis交互、Jedis连接池JedisPool
Java与redis交互比较常用的是Jedis. 先导入jar包: commons-pool2-2.3.jar jedis-2.7.0.jar 基本使用: public class RedisTest ...
- tp杂记
/** php中的大U函数三个参数: U('ajaxDelPic') ==> /index.php/Admin/Goods/ajaxDelPic.html U('ajaxDelPic?id=1' ...
- 如何使用 JMeter 调用你的 Restful Web Service?进行简单的压力测试和自动化测试
表述性状态传输(REST)作为对基于 SOAP 和 Web 服务描述语言(WSDL)的 Web 服务的简单替代,在 Web 开发上得到了广泛的接受.能够充分证明这点的是主流 Web 2.0 服务提供商 ...
- 解决insert语句插入时,需要写列值的问题
今天发现解决这个问题其实很简单,闲话不多谈,我直接附上语句 ) select @s = isnull(@s+',', '') + [name] from syscolumns where id = o ...
- python 统计MySQL大于100万的表
一.需求分析 线上的MySQL服务器,最近有很多慢查询.需要统计出行数大于100万的表,进行统一优化. 需要筛选出符合条件的表,统计到excel中,格式如下: 库名 表名 行数 db1 users 1 ...
- Python学习笔记:import sys模块(argv、path、platform、exit)
sys模块是Python标准库中自带的一个模块. sys模块包括了一组非常实用的服务,内含很多函数方法和变量,用来处理Python运行时配置以及资源,从而可以与当前程序之外的系统环境交互,如:Pyth ...