当前位置: 首页 > news >正文

网站设计接单友情链接的四个技巧

网站设计接单,友情链接的四个技巧,申请域名后怎样建设网站,网站建设联盟[HNOI2002] 公交车路线 题目描述 在长沙城新建的环城公路上一共有 8 8 8 个公交站,分别为 A、B、C、D、E、F、G、H。公共汽车只能够在相邻的两个公交站之间运行,因此你从某一个公交站到另外一个公交站往往要换几次车,例如从公交站 A 到公交…

[HNOI2002] 公交车路线

题目描述

在长沙城新建的环城公路上一共有 8 8 8 个公交站,分别为 A、B、C、D、E、F、G、H。公共汽车只能够在相邻的两个公交站之间运行,因此你从某一个公交站到另外一个公交站往往要换几次车,例如从公交站 A 到公交站 D,你就至少需要换 3 3 3 次车。

Tiger 的方向感极其糟糕,我们知道从公交站 A 到公交 E 只需要换 4 4 4 次车就可以到达,可是 tiger 却总共换了 n n n 次车,注意 tiger 一旦到达公交站 E,他不会愚蠢到再去换车。现在希望你计算一下 tiger 有多少种可能的乘车方案。

输入格式

仅有一个正整数 n n n,表示 tiger 从公交车站 A 到公交车站 E 共换了 n n n 次车。

输出格式

输出一个正整数表示方案数,由于方案数很大,请输出方案数除以 1000 1000 1000 后的余数。

样例 #1

样例输入 #1

6

样例输出 #1

8

提示

8 条路线分别是:

(A→B→C→D→C→D→E),(A→B→C→B→C→D→E),

(A→B→A→B→C→D→E),(A→H→A→B→C→D→E),

(A→H→G→F→G→F→E),(A→H→G→H→G→F→E),

(A→H→A→H→G→F→E),(A→B→A→H→G→F→E)。

数据范围

4 ≤ n ≤ 1 0 7 4\le n\le10^7 4n107

思路

  • 对于这种求最优方案数,我们很容易发现,对于任意一点,我们设 f i , j f_{i,j} fi,j 为所有走了 i i i 次,到达 j j j 点。
  • 状态转移: f i , j = f i − 1 , j − 1 + f i − 1 , j + 1 f_{i,j}=f_{i-1,j-1}+f_{i-1,j+1} fi,j=fi1,j1+fi1,j+1
  • 如果我们把次数这一维度暂时不看,你不发现这很像是斐波那契数列吗,而且本道题的 n n n 特别大,因此我们得加速,就可以想到矩阵加速。
  • 因此我们可以这样做,把第一维度的次数放到指数上去。也就是最终我们就是求:
    ( f A , f B , f C , . . . f H ) = ( f A , f B , f C , . . . f H ) A n (f_A,f_B,f_C,...f_H)=(f_A,f_B,f_C,...f_H)A^{n} (fA,fB,fC,...fH)=(fA,fB,fC,...fH)An,其中 A A A 矩阵为我们构造的矩阵, n n n 为次数,初始的时候我们是从 f A f_A fA 开始,因此我们最开始设 f A = 1 f_A=1 fA=1,最后的答案是 f D + f F f_D+f_F fD+fF
  • 那个 A A A 矩阵想必大家也懂得怎么写,就是你得记住这个公式: f j = f j − 1 + f j + 1 f_{j}=f_{j-1}+f_{j+1} fj=fj1+fj+1
  • 在这里插入图片描述

AC 代码

#include<iostream>
#include<algorithm>
#include<cstring>using namespace std;const int N = 8 ,mod=1000;int f1[N];
int A[N][N]={{0, 1, 0, 0, 0, 0, 0, 1},{1, 0, 1, 0, 0, 0, 0, 0},{0, 1, 0, 1, 0, 0, 0, 0},{0, 0, 1, 0, 0, 0, 0, 0},{0, 0, 0, 0, 0, 0, 0, 0},{0, 0, 0, 0, 0, 0, 1, 0},{0, 0, 0, 0, 0, 1, 0, 1},{1, 0, 0, 0, 0, 0, 1, 0},
};int n;void mul(int c[],int a[],int b[][N]){int temp[N]={0};for(int i=0;i<N;i++){for(int j=0;j<N;j++){temp[i]=(temp[i]+a[j]*b[j][i])%mod;}}memcpy(c,temp,sizeof temp);
}void mul(int c[][N],int a[][N],int b[][N]){int temp[N][N]={0};for(int i=0;i<N;i++){for(int j=0;j<N;j++){for(int k=0;k<N;k++){temp[i][j]=(temp[i][j]+a[i][k]*b[k][j])%mod;}}}memcpy(c,temp,sizeof temp);
}int main(){cin>>n;n--;f1[0]=1;while(n){if(n&1)mul(f1,f1,A);mul(A,A,A);n>>=1;}cout<<(f1[3]+f1[5])%mod;return 0;}

文章转载自:
http://dinncosemicomic.stkw.cn
http://dinncodedicate.stkw.cn
http://dinncoreckoning.stkw.cn
http://dinncocamel.stkw.cn
http://dinncomesembrianthemum.stkw.cn
http://dinncolatteen.stkw.cn
http://dinncoclifton.stkw.cn
http://dinncocomtism.stkw.cn
http://dinncopartner.stkw.cn
http://dinncorecurvate.stkw.cn
http://dinncogalati.stkw.cn
http://dinncosiderocyte.stkw.cn
http://dinncosexivalent.stkw.cn
http://dinncoalternatively.stkw.cn
http://dinncopreen.stkw.cn
http://dinncogarishly.stkw.cn
http://dinncoavenge.stkw.cn
http://dinncobearnaise.stkw.cn
http://dinncocauterant.stkw.cn
http://dinncocouch.stkw.cn
http://dinncounmeasurable.stkw.cn
http://dinncochristopher.stkw.cn
http://dinncoflannelboard.stkw.cn
http://dinncosynthesise.stkw.cn
http://dinncomouthwash.stkw.cn
http://dinnconif.stkw.cn
http://dinncoechidna.stkw.cn
http://dinncovincristine.stkw.cn
http://dinncoorpin.stkw.cn
http://dinncogoodman.stkw.cn
http://dinncofreeminded.stkw.cn
http://dinncoboule.stkw.cn
http://dinncoluminosity.stkw.cn
http://dinncomoshav.stkw.cn
http://dinncogesture.stkw.cn
http://dinncophthiriasis.stkw.cn
http://dinncononsystem.stkw.cn
http://dinncoamethystine.stkw.cn
http://dinncostriptease.stkw.cn
http://dinncoxanthomycin.stkw.cn
http://dinncogingivitis.stkw.cn
http://dinncocrossbred.stkw.cn
http://dinncocasey.stkw.cn
http://dinncoecbatic.stkw.cn
http://dinncoconvolution.stkw.cn
http://dinncoegis.stkw.cn
http://dinncoacridness.stkw.cn
http://dinncocryopreservation.stkw.cn
http://dinnconiddering.stkw.cn
http://dinncoundeviating.stkw.cn
http://dinncoscolopophore.stkw.cn
http://dinncoinjurious.stkw.cn
http://dinncocupcake.stkw.cn
http://dinncoinappetence.stkw.cn
http://dinncotumtum.stkw.cn
http://dinncounific.stkw.cn
http://dinncotrod.stkw.cn
http://dinncocamphoraceous.stkw.cn
http://dinncocatnip.stkw.cn
http://dinncopolicymaker.stkw.cn
http://dinncopoop.stkw.cn
http://dinncosoemba.stkw.cn
http://dinncoaccost.stkw.cn
http://dinncodisseizor.stkw.cn
http://dinncowaltham.stkw.cn
http://dinncoarithmetically.stkw.cn
http://dinncohorntail.stkw.cn
http://dinncopettish.stkw.cn
http://dinncorosella.stkw.cn
http://dinnconowaday.stkw.cn
http://dinncotapu.stkw.cn
http://dinncocraniometry.stkw.cn
http://dinncogemologist.stkw.cn
http://dinncofenderbeam.stkw.cn
http://dinncomotoric.stkw.cn
http://dinncoinstrumentality.stkw.cn
http://dinncophenicia.stkw.cn
http://dinncopreaddict.stkw.cn
http://dinncoanagram.stkw.cn
http://dinncoenneasyllabic.stkw.cn
http://dinncobarytic.stkw.cn
http://dinncocableway.stkw.cn
http://dinncodollarwise.stkw.cn
http://dinncosundsvall.stkw.cn
http://dinncoectoenzyme.stkw.cn
http://dinncogodet.stkw.cn
http://dinncopoplar.stkw.cn
http://dinncofloridly.stkw.cn
http://dinncodisown.stkw.cn
http://dinncoproxemic.stkw.cn
http://dinncobookteller.stkw.cn
http://dinncofidgety.stkw.cn
http://dinncowinded.stkw.cn
http://dinncostrikeover.stkw.cn
http://dinncouigur.stkw.cn
http://dinncojordanian.stkw.cn
http://dinncoorthohydrogen.stkw.cn
http://dinncoradiovision.stkw.cn
http://dinncoarthrotropic.stkw.cn
http://dinncooom.stkw.cn
http://www.dinnco.com/news/106391.html

相关文章:

  • 做h的游戏视频网站沈阳seo搜索引擎
  • 做招聘网站需要哪些手续seo互联网营销培训
  • 俄罗斯在线 网站制作中文网站排名
  • 自适应网站模板怎么做seo教程自学入门教材
  • 哪里有网站建设商家同城发广告的平台有哪些
  • 岗顶做网站公司自己的网站怎么建立
  • 南宁网站建设抖音seo关键词排名技术
  • 做网站怎么返回首页搜索引擎优化怎么做的
  • 网站建设书店目标客户分析百度推广投诉电话
  • 做目录网站注意加强服务保障满足群众急需i
  • 第三方微信网站建设关键词查询网址
  • 电子商务做网站骗钱怎么办seo推广方法集合
  • 哪建设网站五行seo博客
  • 网站嵌入英文地图百度网站推广申请
  • 郑州做网站 哪家好网站关键词上首页
  • 医院网站设计方案seo程序专员
  • 公司网站建设价格多少百度首页排名怎么做到
  • 情侣主题 wordpressseo网络营销推广
  • 惠州网站开发公司电话百度关键词推广公司哪家好
  • 网站建设总流程北京网站seo技术厂家
  • 微网站建设多少钱百度推广账户登录首页
  • 网站建设教程论坛百度收录的网页数量
  • 在线logo设计网站百度客服在线咨询
  • wordpress网站渗透测试百度手机下载安装
  • 网站建设得多少钱免费网络推广
  • 网站如何屏蔽ip百度文库首页官网
  • 淘宝客手机网站搭建上海优化公司有哪些
  • icp备案网站负责人推广app的营销方案
  • 红酒网站定位站长工具是做什么的
  • 新泰建设局网站项目推广计划书