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)模型,这是一个用于检查数据的参数生存回归模型. 它描述了生存时间对数的模型,因此它通常被称为生存分析的对数线性模型. 不同于为相同目的设计的比例风险模 ...
随机推荐
- iOS学习笔记(2)— UIView用户事件响应
UIView除了负责展示内容给用户外还负责响应用户事件.本章主要介绍UIView用户交互相关的属性和方法. 1.交互相关的属性 userInteractionEnabled 默认是YES ,如果设置为 ...
- JSP中page,request,session,application四个域对象区别
page page指当前页面.只在一个jsp页面里有效 . page里的变量没法从index.jsp传递到test.jsp,只要页面跳转了,它们就不见了. pageContext 如果把变量放到pag ...
- 20 Organizing Go code 组织go代码
Organizing Go code 16 August 2012 Introduction Go code is organized differently to that of other lan ...
- 栈应用之 后缀表达式计算 (python 版)
栈应用之 后缀表达式计算 (python 版) 后缀表达式特别适合计算机处理 1. 中缀表达式.前缀表达式.后缀表达式区别 中缀表达式:(3 - 5) * (6 + 17 * 4) / 3 17 ...
- PHP获得用户的真实IP地址
<?php /** * 获得用户的真实IP地址 * * @access public * @return string */ function real_ip() { static $reali ...
- python基础--json,pickle和shelve模块
一.JSON &pickle 用于序列化的两个模块 json,用于字符串 和 python数据类型间进行转换 字符串必须是双引号,不能是单引号 pickle,用于python特有的类型 和 ...
- Linux学习笔记:wc查看文件字节数、字数、行数
Linux系统中的wc(Word Count)命令可以统计指定文件中的字节数.字数.行数,并将统计结果显示输出. 若不指定文件名称,或是所给予的文件名为“-”,则wc指令会从标准输入设备读取数据. 语 ...
- » Working Around JNI UTF-8 Strings Deprogramming
private static native void printString(String text); ... void examplePrintString() { String str = &q ...
- 基于CommonsChunkPlugin,webpack打包优化
前段时间一直在基于webpack进行前端资源包的瘦身.在项目中基于路由进行代码分离,http://www.cnblogs.com/legu/p/7251562.html.但是打包的文件还是很大,特别是 ...
- <未来世界的幸存者> 读后感(现实篇和职业篇)【原创】
摘要: 前几天有幸看到阮老师的 <未来世界的幸存者)>,花了几晚的时间阅读完毕,内心受到了很大的触动,现在将感觉不错的地方记录下. 职业篇 1. 为什么雇佣制度对工人不利? 雇佣制度是一种 ...