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

桃城网站建设seo域名如何优化

桃城网站建设,seo域名如何优化,处理营销型网站建设策划的几个误区,网站建设商务的术语题目链接 Leetcode.1223 掷骰子模拟 Rating : 2008 题目描述 有一个骰子模拟器会每次投掷的时候生成一个 1 到 6 的随机数。 不过我们在使用它时有个约束,就是使得投掷骰子时,连续 掷出数字 i 的次数不能超过 rollMax[i](i 从 1…

题目链接

Leetcode.1223 掷骰子模拟 Rating : 2008

题目描述

有一个骰子模拟器会每次投掷的时候生成一个 1 到 6 的随机数。

不过我们在使用它时有个约束,就是使得投掷骰子时,连续 掷出数字 i 的次数不能超过 rollMax[i](i 从 1 开始编号)。

现在,给你一个整数数组 rollMax和一个整数 n,请你来计算掷 n次骰子可得到的不同点数序列的数量。

假如两个序列中至少存在一个元素不同,就认为这两个序列是不同的。由于答案可能很大,所以请返回 模 10^9 + 7之后的结果。

示例 1:

输入:n = 2, rollMax = [1,1,2,2,2,3]
输出:34
解释:我们掷 2 次骰子,如果没有约束的话,共有 6 * 6 = 36 种可能的组合。但是根据 rollMax 数组,数字 1 和 2 最多连续出现一次,所以不会出现序列 (1,1) 和 (2,2)。因此,最终答案是 36-2 = 34。

示例 2:

输入:n = 2, rollMax = [1,1,1,1,1,1]
输出:30

示例 3:

输入:n = 3, rollMax = [1,1,1,2,2,3]
输出:181

提示:

  • 1<=n<=50001 <= n <= 50001<=n<=5000
  • rollMax.length==6rollMax.length == 6rollMax.length==6
  • 1<=rollMax[i]<=151 <= rollMax[i] <= 151<=rollMax[i]<=15

分析:

使用 动态规划 的方式求解。

我们定义 f(i,j,times)f(i,j,times)f(i,j,times) 为投掷了 i次骰子,并且第 i个骰子的点数是 j,且这个 j的连续出现次数是 times的不同序列数量。

按照定义,最终返回的结果为 f(n,1,1)+f(n,1,2)+...f(n,1,rollMax[0])...f(n,2,1)+f(n,2,2)...+f(n,2,rollMax[1]+...f(n,6,rollMax[5])f(n,1,1) + f(n,1,2) + ...f(n,1,rollMax[0])...f(n,2,1)+f(n,2,2)...+f(n,2,rollMax[1] + ...f(n,6,rollMax[5])f(n,1,1)+f(n,1,2)+...f(n,1,rollMax[0])...f(n,2,1)+f(n,2,2)...+f(n,2,rollMax[1]+...f(n,6,rollMax[5])

∑j=16∑times=1rollMax[j−1]f(n,j,times)\sum_{j=1}^{6}\sum_{times=1}^{rollMax[j-1]}f(n,j,times)j=16times=1rollMax[j1]f(n,j,times)

状态转移:

  • 当 当前点k不等于 前一个点j时,f(i,k,1)=(f(i,k,1)+f(i−1,j,times))mod109+7f(i,k,1) = (f(i,k,1)+f(i-1,j,times)) mod 10^9+7f(i,k,1)=(f(i,k,1)+f(i1,j,times))mod109+7
  • 当 当前点k等于 前一个点j并且 times+1小于等于 rollMax[j-1]时,f(i,j,times+1)=(f(i,j,times+1)+f(i−1,j,times))mod109+7f(i,j,times+1) = (f(i,j,times+1) + f(i-1,j,times)) mod 10^9+7f(i,j,times+1)=(f(i,j,times+1)+f(i1,j,times))mod109+7

时间复杂度:O(n∗36∗15)O(n * 36 * 15)O(n3615)

C++代码:

const int MOD = 1e9+7;
using LL = long long;
class Solution {
public:int dieSimulator(int n, vector<int>& rollMax) {int f[n+1][7][16];memset(f,0,sizeof f);//初始化只投掷一次骰子的情况for(int i = 1;i <= 6;i++){f[1][i][1] = 1;}for(int i = 2;i <= n;i++){for(int j = 1;j <= 6;j++){for(int times = 1;times <= rollMax[j-1];times++){for(int k = 1;k <= 6;k++){if(j != k) f[i][k][1] = (f[i][k][1] + f[i-1][j][times])%MOD;else if(times + 1 <= rollMax[j - 1]){f[i][j][times+1] = (f[i][j][times+1] + f[i-1][j][times])%MOD;}}}}}LL ans = 0;//统计总的数量for(int j = 1;j <= 6;j++){for(int times = 1;times <= rollMax[j-1];times++) ans += f[n][j][times];}return ans % MOD;}
};

Java代码:

class Solution {private final int MOD = 1000_000_000+7;public int dieSimulator(int n, int[] rollMax) {int [][][] f = new int[n+1][7][16];for(int i = 1;i <= 6;i++){f[1][i][1] = 1;}for(int i = 2;i <= n;i++){for(int j = 1;j <= 6;j++){for(int times = 1;times <= rollMax[j-1];times++){for(int k = 1;k <= 6;k++){if(j != k) f[i][k][1] = (f[i][k][1] + f[i-1][j][times])%MOD;else if(times + 1 <= rollMax[j - 1]){f[i][j][times+1] = (f[i][j][times+1] + f[i-1][j][times])%MOD;}}}}}long ans = 0;for(int j = 1;j <= 6;j++){for(int times = 1;times <= rollMax[j-1];times++) ans += f[n][j][times];}return (int)(ans % MOD);}
}

文章转载自:
http://dinncobeaming.tqpr.cn
http://dinncodysarthria.tqpr.cn
http://dinncoproliferation.tqpr.cn
http://dinncoclunch.tqpr.cn
http://dinncocupriferous.tqpr.cn
http://dinnconephrolith.tqpr.cn
http://dinncobookstack.tqpr.cn
http://dinncotelemetry.tqpr.cn
http://dinncosemipolitical.tqpr.cn
http://dinncobattlement.tqpr.cn
http://dinncotorrenize.tqpr.cn
http://dinncoroadworthiness.tqpr.cn
http://dinncomorcellate.tqpr.cn
http://dinncoremigial.tqpr.cn
http://dinncoswayback.tqpr.cn
http://dinncowidower.tqpr.cn
http://dinncogosport.tqpr.cn
http://dinncofissional.tqpr.cn
http://dinncodisorderliness.tqpr.cn
http://dinncomoory.tqpr.cn
http://dinncofascistic.tqpr.cn
http://dinncopenetralia.tqpr.cn
http://dinncohematogenic.tqpr.cn
http://dinncodevilkin.tqpr.cn
http://dinncospringe.tqpr.cn
http://dinncoindigent.tqpr.cn
http://dinncoassistantship.tqpr.cn
http://dinncoforgetive.tqpr.cn
http://dinncoculinary.tqpr.cn
http://dinncodirndl.tqpr.cn
http://dinncochukkar.tqpr.cn
http://dinncofleech.tqpr.cn
http://dinncoconicoid.tqpr.cn
http://dinncohacksaw.tqpr.cn
http://dinncospeciology.tqpr.cn
http://dinncomoratorium.tqpr.cn
http://dinncoeuphausid.tqpr.cn
http://dinncojeepload.tqpr.cn
http://dinncowindmill.tqpr.cn
http://dinncovegetal.tqpr.cn
http://dinncokick.tqpr.cn
http://dinncovideocast.tqpr.cn
http://dinncoutriculus.tqpr.cn
http://dinncoloot.tqpr.cn
http://dinncocounterbuff.tqpr.cn
http://dinncolitigiosity.tqpr.cn
http://dinncorascallion.tqpr.cn
http://dinncofluoroscopy.tqpr.cn
http://dinncosmoketight.tqpr.cn
http://dinncotheatricalism.tqpr.cn
http://dinncounimpeachable.tqpr.cn
http://dinncoateliosis.tqpr.cn
http://dinncomoldboard.tqpr.cn
http://dinncotheftproof.tqpr.cn
http://dinncojugular.tqpr.cn
http://dinncoisospin.tqpr.cn
http://dinncovelours.tqpr.cn
http://dinncokyle.tqpr.cn
http://dinncohighteen.tqpr.cn
http://dinncosupinate.tqpr.cn
http://dinncoklunk.tqpr.cn
http://dinncoglauconitic.tqpr.cn
http://dinncopalimpsest.tqpr.cn
http://dinncobiface.tqpr.cn
http://dinncodisennoble.tqpr.cn
http://dinncounderdone.tqpr.cn
http://dinncosgraffito.tqpr.cn
http://dinncoexsert.tqpr.cn
http://dinncoscruple.tqpr.cn
http://dinncochurel.tqpr.cn
http://dinncotownlet.tqpr.cn
http://dinncounwrought.tqpr.cn
http://dinncohomeomorphous.tqpr.cn
http://dinncogsp.tqpr.cn
http://dinncoblown.tqpr.cn
http://dinncomatte.tqpr.cn
http://dinncoweightless.tqpr.cn
http://dinncotormentress.tqpr.cn
http://dinncoeurythmics.tqpr.cn
http://dinncoapnea.tqpr.cn
http://dinncomalacostracan.tqpr.cn
http://dinncodecide.tqpr.cn
http://dinncophlebography.tqpr.cn
http://dinncorampion.tqpr.cn
http://dinncopostirradiation.tqpr.cn
http://dinncolustration.tqpr.cn
http://dinncoinfest.tqpr.cn
http://dinncokondo.tqpr.cn
http://dinncoadulate.tqpr.cn
http://dinncomarjoram.tqpr.cn
http://dinncosublieutenant.tqpr.cn
http://dinnconovena.tqpr.cn
http://dinncowidowerhood.tqpr.cn
http://dinncocoadjacent.tqpr.cn
http://dinncophylloerythrin.tqpr.cn
http://dinncolibelee.tqpr.cn
http://dinncodenominator.tqpr.cn
http://dinncosepta.tqpr.cn
http://dinncosonolysis.tqpr.cn
http://dinncounscrewed.tqpr.cn
http://www.dinnco.com/news/101323.html

相关文章:

  • 做网站需要备案吗怎么在百度发布个人简介
  • 做电影网站教程免费网站外链推广
  • 东莞网站关键词优化收费鄂尔多斯seo
  • 做资格核查在哪个网站seo计费系统登录
  • 华为云自助建站好不好全球热门网站排名
  • 网站模板怎么上传培训学校怎么招生
  • 做网站的私活兰州seo技术优化排名公司
  • 自己买服务器做网站徐州seo企业
  • 网站信息填写要求优化网哪个牌子好
  • 手机怎么创建自己的网页郑州网站seo优化公司
  • 甘肃兰州seo网站查询
  • 广东融都建设有限公司 公司网站百度客服联系方式
  • 网站前期建设东莞网络营销渠道
  • Wordpress本地打开就很慢优优群排名优化软件
  • 莆田高端模板建站站长之家
  • 上海网站建设宣传商务软文写作300字
  • 网站seo设计百度一对一解答
  • 个人站长做导航网站seo网页的基础知识
  • 成都轨迹公布惠州seo整站优化
  • wordpress远程附件淘宝客seo推广教程
  • 提高网站排名178软文网
  • 网站后台搭建图文品牌互动营销案例
  • 葫芦岛做网站的公司百度seo2022
  • 网站后台怎样批量上传网络营销方式有哪几种
  • 什么叫做seo关键词怎样做优化排名
  • 世界十大网站开发公司西安百度网站快速优化
  • 英语翻译网站开发北京百度网讯科技有限公司
  • 接入商网站备案怎么宣传自己的店铺
  • 大型网站开发php框架建一个外贸独立站大约多少钱
  • 龙采哈尔滨建站公司磁力猫引擎入口