BZOJ3868 : The only survival

枚举每个点到$1$的距离,若$>k$则视为$k+1$,那么$d_1=1,d_n=k$。

对于$i$,如果$1\leq d_i\leq k$,则一定要存在一条边长度为$d_i-d_j$,且其他边长度都要$\geq d_i-d_j$。

如果$d_i>k$,那么对于每条边都满足长度$>k-d_j$。

枚举每个$d$的个数,通过排列组合进行指派,然后通过DP计算方案数。

状态为$f[i][j]$表示$x$考虑了$1$到$i$这些点的连边,是否存在一条边使得这个距离合法的方案数。

时间复杂度$O(nB(n))$。

#include<cstdio>
const int N=15,P=1000000007;
int T,n,k,L,i,j,C[N][N],d[N],now,ret,f[2],ans;
inline int fix(int x){return x<L?x:L;}
void dfs(int x,int y,int z,int now){
  if(x==2&&y==0)return;
  d[x]=y;z|=y==k;
  if(x>1)if(y<=k){
    f[0]=1,f[1]=0;
    for(i=1;i<x;i++)if(d[i]==y){
      f[0]=1LL*f[0]*L%P;
      f[1]=1LL*f[1]*L%P;
    }else{
      f[1]=(1LL*f[1]*(L-y+d[i]+1)+f[0])%P;
      f[0]=1LL*f[0]*(L-y+d[i])%P;
    }
    now=1LL*now*f[1]%P;
  }else for(i=1;i<x;i++)now=1LL*now*fix(L-k+d[i])%P;
  if(x==n){
    if(!z)return;
    for(ret=n-2,i=2;i<=n;i=j){
      for(j=i;j<=n&&d[i]==d[j];j++);
      if(d[i]==k)i++;
      now=1LL*now*C[ret][j-i]%P;
      ret-=j-i;
    }
    ans=(ans+now)%P;
    return;
  }
  for(;y<=k+1;y++)dfs(x+1,y,z,now);
}
int main(){
  for(C[0][0]=i=1;i<N;i++)for(C[i][0]=j=1;j<=i;j++)C[i][j]=(C[i-1][j-1]+C[i-1][j])%P;
  scanf("%d",&T);
  while(T--){
    scanf("%d%d%d",&n,&k,&L);
    if(n==1||k>L){puts("0");continue;}
    if(n==2){puts("1");continue;}
    dfs(1,ans=0,0,1);
    printf("%d\n",ans);
  }
  return 0;
}

  

时间: 2024-08-02 21:48:41

BZOJ3868 : The only survival的相关文章

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

生存分析,survival analysis,顾名思义是用来研究个体的存活概率与时间的关系.例如研究病人感染了病毒后,多长时间会死亡:工作的机器多长时间会发生崩溃等.  这里“个体的存活”可以推广抽象成某些关注的事件. 所以SA就成了研究某一事件与它的发生时间的联系的方法.这个方法广泛的用在医学.生物学等学科上,近年来也越来越多人用在互联网数据挖掘中,例如用survival analysis去预测信息在社交网络的传播程度,或者去预测用户流失的概率. R里面有很成熟的SA工具. 本文介绍生存分析的

zoj 2297 Survival 状压dp

Description The King of Fighter 97 (KOF97) is an electronic game of wrestling type. Once it was fashionable among youths. The game is amused. However, playing by oneself is not as excited as with friends. Getting bored? Maybe you can alter to the sur

(转) 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”, a post I wrote a long time ago on some of the tips/tricks I’ve developed during my undergrad. I’ve received nice comments about that guide, so in the

JSBinding + SharpKit / 实战:转换 Survival Shooter

从 asset store 下载 Survival Shooter Unity4.6 版本用的那个 删除多余的代码及文件夹 /Scripts/       <-- 因为没有用 /Scenes/       <-- 因为是空的 /Animation/   <-- 因为是空的 /Prefabs/Hellephant.prefab /Prefabs/ZomBear.prefab 删完后应该是这样的: 执行菜单:Mobile Input | Disable 添加 Coroutine-Update

Spark2 生存分析Survival regression

在spark.ml中,实现了加速失效时间(AFT)模型,这是一个用于检查数据的参数生存回归模型. 它描述了生存时间对数的模型,因此它通常被称为生存分析的对数线性模型. 不同于为相同目的设计的比例风险模型,AFT模型更容易并行化,因为每个实例独立地贡献于目标函数. 当在具有常量非零列的数据集上匹配AFTSurvivalRegressionModel而没有截距时,Spark MLlib为常量非零列输出零系数. 这种行为不同于R survival :: survreg. 导入包 import org.

light oj 1265 - Island of Survival(概率dp)

1265 - Island of Survival PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB You are in a reality show, and the show is way too real that they threw into an island. Only two kinds of animals are in the island, the tigers and t

LightOJ 1265 Island of Survival 概率DP

H - Island of Survival Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1265 Description You are in a reality show, and the show is way too real that they threw into an island. Only two kinds o

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

推荐大家一本书尤其是即将读研究生或者研一研二的学生:                                                     A Mathematician‘s  Survival Guide                                                         Graduate School and  Early Career Development                                    

ZOJ Problem Set - 2297 Survival 【状压dp】

题目:ZOJ Problem Set - 2297 Survival 题意:给出一些怪,有两个值,打他花费的血和可以增加的血,然后有一个boss,必须把小怪所有都打死之后才能打boss,血量小于0会死,也不能大于100. 分析:定义状态:dp[st],表示在 st 状态下的血量. 然后转移:dp[st] = max (dp[st],dp[st&~(1<<i )]+p[i].first - p[i].second); 注意初始化的时候必须在开始初始化,否则容易出错. #include &