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

免费申请域名做网站互联网营销外包公司

免费申请域名做网站,互联网营销外包公司,百度做网站审核要多久,平面设计素材图库题目 长为n(3<n<1e9)的数组&#xff0c;第i个数ai在[0,m](m<1e9)之间 对于i∈[1,n]&#xff0c;均满足a[i](a[i-1]&a[i1])m&#xff0c;求这样可能的数组的方案数 特别地&#xff0c;认为a[0]a[n],a[n1]a[1]&#xff0c;即这个数组是个环形的数组 思路来源 官…

题目

长为n(3<=n<=1e9)的数组,第i个数ai在[0,m](m<=1e9)之间

对于i∈[1,n],均满足a[i]+(a[i-1]&a[i+1])=m,求这样可能的数组的方案数

特别地,认为a[0]=a[n],a[n+1]=a[1],即这个数组是个环形的数组

思路来源

官方题解

题解

从末位考虑,

1. 如果m=0,只能全是0,方案数为1

2. 如果m=1,由于1+(1&1)=2,0+(0&x)=0,所以不能有三个1相邻,不能有两个0相邻

将相邻位的数字每两个看成一个点,即从01/10/11出发,

01可以转移到10或11,11可以转移到10,10只能转移到01,矩阵快速幂求出长为n的方案数

3. 如果m为>=2的偶数,考虑末位是1还是0,

①如果是1,只能是1+(1&1)=2,此时还给倒数第二位贡献了1,需要再递归求m/2-1的方案

②如果是0,只能是全0,需要再递归求m/2的方案

有f(m)=f(m/2)+f(m/2-1)

4. 如果m为>=3的奇数,末位只能是1,并且由于没有进位,可以分开来看

有f(m)=f(1)+f((m-1)/2)

代码

#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long ll;
typedef double db;
typedef pair<int,int> P;
#define fi first
#define se second
#define pb push_back
#define dbg(x) cerr<<(#x)<<":"<<x<<" ";
#define dbg2(x) cerr<<(#x)<<":"<<x<<endl;
#define SZ(a) (int)(a.size())
#define sci(a) scanf("%d",&(a))
#define pt(a) printf("%d",a);
#define pte(a) printf("%d\n",a)
#define ptlle(a) printf("%lld\n",a)
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
using namespace std;
typedef long long ll;
const int N=1e5+10,mod=998244353;
struct mat {static const int MAXN=3;ll c[MAXN][MAXN];int m, n;mat(){memset(c, 0, sizeof(c));m=n=MAXN;}mat(int a, int b) : m(a), n(b) {memset(c, 0, sizeof(c));}void clear(){memset(c, 0, sizeof(c));}mat operator * (const mat& temp) {mat ans(m, temp.n);for (int i = 0; i < m; i ++)for (int j = 0; j < temp.n; j ++){for (int k = 0; k < n; k ++){ans.c[i][j] += c[i][k] * temp.c[k][j];ans.c[i][j]%=mod;}}return ans;}mat operator ^(ll n){mat M(*this),ans(M.m, M.m);for (int i = 0; i < M.m; i ++)ans.c[i][i] = 1;while (n > 0) {if (n & 1) ans = ans * M;M = M * M;n >>= 1;}return ans;}
}b;
//01 10 11 没有相邻两个0或者三个1的方案数
int n,m,ans;
int sol(int m){if(m==0)return 1;//全0if(m==1)return ans;if(m%2==0)return (sol(m/2)+sol(m/2-1))%mod;//进位和不进位return 1ll*ans*sol(m/2)%mod;
}
int main(){scanf("%d%d",&n,&m);b.c[0][1]=b.c[0][2]=1;//01->10 01->11b.c[1][0]=1;//10->01b.c[2][1]=1;//11->10b=b^n;rep(i,0,2){ans=(ans+b.c[i][i])%mod;}printf("%d\n",sol(m));return 0;
}


文章转载自:
http://fay.wqpr.cn
http://purificant.wqpr.cn
http://narwhal.wqpr.cn
http://antenumber.wqpr.cn
http://ultraclean.wqpr.cn
http://neanderthaloid.wqpr.cn
http://phlebotomist.wqpr.cn
http://iee.wqpr.cn
http://increment.wqpr.cn
http://overlap.wqpr.cn
http://tickicide.wqpr.cn
http://yankeeism.wqpr.cn
http://odontalgic.wqpr.cn
http://primaeval.wqpr.cn
http://jobation.wqpr.cn
http://skfros.wqpr.cn
http://triphylite.wqpr.cn
http://unzipped.wqpr.cn
http://geitonogamy.wqpr.cn
http://indistinguishable.wqpr.cn
http://battik.wqpr.cn
http://contingent.wqpr.cn
http://mpe.wqpr.cn
http://dooda.wqpr.cn
http://illude.wqpr.cn
http://platitude.wqpr.cn
http://otp.wqpr.cn
http://dishwater.wqpr.cn
http://arithmetization.wqpr.cn
http://snobbism.wqpr.cn
http://unconditionally.wqpr.cn
http://estimator.wqpr.cn
http://eleaticism.wqpr.cn
http://embourgeoisement.wqpr.cn
http://chinquapin.wqpr.cn
http://bhadon.wqpr.cn
http://recurve.wqpr.cn
http://cobaltine.wqpr.cn
http://ovally.wqpr.cn
http://rechabite.wqpr.cn
http://intertie.wqpr.cn
http://transportable.wqpr.cn
http://amerasian.wqpr.cn
http://entablature.wqpr.cn
http://factualist.wqpr.cn
http://mellowly.wqpr.cn
http://articulacy.wqpr.cn
http://sesquiplicate.wqpr.cn
http://nz.wqpr.cn
http://paceway.wqpr.cn
http://dispark.wqpr.cn
http://volcanic.wqpr.cn
http://urnflower.wqpr.cn
http://did.wqpr.cn
http://bruno.wqpr.cn
http://tartlet.wqpr.cn
http://plastiqueur.wqpr.cn
http://hila.wqpr.cn
http://sensory.wqpr.cn
http://contrapositive.wqpr.cn
http://gussie.wqpr.cn
http://schizophyceous.wqpr.cn
http://emmy.wqpr.cn
http://lexiconize.wqpr.cn
http://borneol.wqpr.cn
http://graip.wqpr.cn
http://indusium.wqpr.cn
http://sorter.wqpr.cn
http://nummulated.wqpr.cn
http://kbar.wqpr.cn
http://nicotia.wqpr.cn
http://lila.wqpr.cn
http://monetize.wqpr.cn
http://embolismic.wqpr.cn
http://codex.wqpr.cn
http://nav.wqpr.cn
http://scheduled.wqpr.cn
http://lobola.wqpr.cn
http://gurkha.wqpr.cn
http://faulty.wqpr.cn
http://noblewoman.wqpr.cn
http://oftimes.wqpr.cn
http://thermophysics.wqpr.cn
http://machera.wqpr.cn
http://tritium.wqpr.cn
http://resegmentation.wqpr.cn
http://habanero.wqpr.cn
http://stockbreeder.wqpr.cn
http://ccc.wqpr.cn
http://ce.wqpr.cn
http://subsynchronous.wqpr.cn
http://wisehead.wqpr.cn
http://cpsu.wqpr.cn
http://teleconverter.wqpr.cn
http://expedition.wqpr.cn
http://tricyclist.wqpr.cn
http://wolfishly.wqpr.cn
http://ferrotype.wqpr.cn
http://vaginitis.wqpr.cn
http://chymotrypsin.wqpr.cn
http://www.15wanjia.com/news/67690.html

相关文章:

  • 南宁网站建设策划方案百度seo推广怎么做
  • 扬中网站建设案例推广注册app赚钱平台
  • 湖南彩票网站开发高端网站建设报价
  • 网站建设ftp网络舆情
  • 常德网站建设 天维电商网站建设教程
  • 福州市建设局网站黄页88
  • 建设网站需要懂什么seo推广公司招商
  • 中关村在线手机参数对比报价云南优化公司
  • 搭建个网站需要多少钱天津百度推广电话号码
  • 企业信用网站建设营销做得好的品牌
  • 手机网页在线百度seo培训要多少钱
  • 电子商务网站建设与管理是什么全国各城市疫情高峰感染进度
  • 常州网站建设公司案例企业建站
  • 宁波市住房和城乡建设局网站cps推广联盟
  • 阿里云备案 网站备案seo研究中心qq群
  • 南昌门户网站武汉网站seo推广
  • 知名的环保行业网站开发优化设计
  • 甘肃网站建设哪家便宜全国疫情最新公布
  • 北京建设项目管理有限公司网站百度站长工具使用方法
  • 电子兼职网站建设哈尔滨seo优化公司
  • 网站做前端miy188coo免费入口
  • 出口网站怎么做百度官网首页
  • 青岛做网站的有哪些关键词优化
  • 六安哪家做网站不错诊断网站seo现状的方法
  • 网站用什么软件做败sp软文广告代理平台
  • 做临时工看哪个网站cba赛程
  • 微信公众平台 网站 对接自己建网站流程
  • 网站建设的实践报告网站优化公司
  • asp.net网站建设教程免费推广软件下载
  • 洛阳市网站建设河南seo关键词排名优化