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)模型,这是一个用于检查数据的参数生存回归模型. 它描述了生存时间对数的模型,因此它通常被称为生存分析的对数线性模型. 不同于为相同目的设计的比例风险模 ...
随机推荐
- 树形dp&&树的重心(D - Godfather POJ - 3107)
题目链接:https://cn.vjudge.net/contest/277955#problem/D 题目大意:求树的重心(树的重心指的是树上的某一个点,删掉之后形成的多棵树中节点数最大值最小). ...
- 说说C语言运算符的“优先级”与“结合性”
论坛和博客上常常看到关于C语言中运算符的迷惑,甚至是错误的解读.这样的迷惑或解读大都发生在表达式中存在着较为复杂的副作用时.但从本质上看,仍然是概念理解上的偏差.本文试图通过对三个典型表达式的分析,集 ...
- 2016.5.18——Excel Sheet Column Number
Excel Sheet Column Number 本题收获: 1.对于字符串中字母转为ASIIC码:string s ;res = s[i]-'A'; 这个res就是数字s[i]-'A'是对ASII ...
- 【HASPDOG】卸载
rpm -qa | grep aksusdb rpm -e aksusdb... rm -rf /var/hasplm
- aarch64_l1
L-function-1.23-18.fc26.aarch64.rpm 2017-02-14 08:01 139K fedora Mirroring Project L-function-devel- ...
- 「要买车网」免费获取汽车电商要买车网购车优惠券 - 持续更新(2016-03-12)www.fortunelab.cn
汽车电商要买车网简介 “要买车”(www.yaomaiche.com)网站是上海运图投资有限公司旗下网站,是首家真正打通交易闭环的汽车电商网站,由中国电子商务成功探索者——卜广齐于2014年10月在上 ...
- ios 个人开发者账户 给其他团队用坑爹的教程
最新版本的 ios 支持 3个开发者证书 和 3个发布者证书 ,如果是多余3台电脑设备要真机调试,就比较麻烦 (手机支持100个设备) 解决方案就是: 在别人的电脑上要成功安装,须具备两个文件: ...
- 使用PyMongo访问需要认证的MongoDB
Windows 10家庭中文版,Python 3.6.4,PyMongo 3.7.0,MongoDB 3.6.3,Scrapy 1.5.0, 前言 在Python中,使用PyMongo访问Mongod ...
- css同时满足两个类名才有效果的写法
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- wpf mvvm模式下的image绑定
view文件 <Image Grid.Column="2" Width="48" Height="64" Stretch=" ...