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

设计的网站源代码怎么做营销推广活动策划

设计的网站源代码怎么做,营销推广活动策划,网站备案是否收费,宜昌市城市建设学校网站目录 一,3178. 找出 K 秒后拿着球的孩子 二,3179. K 秒后第 N 个元素的值 三,3180. 执行操作可获得的最大总奖励 I 四,3181. 执行操作可获得的最大总奖励 II 一,3178. 找出 K 秒后拿着球的孩子 本题可以直接模拟&a…

目录

一,3178. 找出 K 秒后拿着球的孩子

二,3179. K 秒后第 N 个元素的值

三,3180. 执行操作可获得的最大总奖励 I

四,3181. 执行操作可获得的最大总奖励 II


一,3178. 找出 K 秒后拿着球的孩子

本题可以直接模拟,遇到 0 或 n - 1 下标,就反转一下。

代码如下:

class Solution {public int numberOfChild(int n, int k) {int i = 0, t = 1;while(k > 0){i += t;if(i == 0 || i == n-1){t *= -1;}k--;}return i;}
}

二,3179. K 秒后第 N 个元素的值

本题也是一道模拟题,对数组 a 不断的求前缀和,最后返回a[n-1].

代码如下:

class Solution {public int valueAfterKSeconds(int n, int k) {int MOD = (int)1e9 + 7;int[] a = new int[n];Arrays.fill(a, 1);while(k > 0){for(int i=1; i<n; i++){a[i] = (a[i] + a[i-1])%MOD;}k--;}return a[n-1];}
}

三,3180. 执行操作可获得的最大总奖励 I

本题可以使用dfs中的选或不选来做,这里需要知道当前的下标 i ,以及前面所选的数的和 x,需要使用 x < rewardValues[i] 来判断该点能否选。(注意,题目对选择的下标没有进行限制,我们可以先将数组排序,这样就只需要向后遍历)

定义 dfs(i,x):在[0,i)所选择的所有数的和为x时,[i,n]的最大总奖励。

  • 选择 i 下标(必须先满足 x < rewardValues[i]),这时下一个状态就是 dfs(i+1,x+rewardValues[i])
  • 不选 i 下标,下一个状态是 dfs(i+1, x)
  • 结束条件,i == n,返回 0
  • 返回两者的较大值

这里记忆化的时候只需要记录 x 就行,我们只需要关注在当前和为 x 时,能取到的最大值memo[x],代码如下:

class Solution {public int maxTotalReward(int[] rewardValues) {Arrays.sort(rewardValues);memo = new int[4001];Arrays.fill(memo, -1);return dfs(0,0,rewardValues);}int[] memo;int dfs(int i, int x, int[] rewardValues){if(memo[x] != -1) return memo[x];if(i == rewardValues.length) return 0;int res = dfs(i+1, x, rewardValues);if(x < rewardValues[i]){res = Math.max(res, dfs(i+1, x+rewardValues[i], rewardValues)+rewardValues[i]);}return memo[x] = res;}
}

递推做法(0-1背包)

定义f[i][j]:能否从前 i 个数得到总奖励为 j

  • 选(满足 j > rewardValues[i] && j-rewardValues[i] < rewardValues[i]),f [ i ][ j ] = f [ i-1 ][ j-rewardValues[i] ]
  • 不选,f [ i ][ j ] = f [ i-1 ][ j ]
  • f [ i ][ j ] = f [ i-1 ][ j ] || f [ i-1 ][ j-rewardValues[i] ]
class Solution {public int maxTotalReward(int[] rewardValues) {Arrays.sort(rewardValues);boolean[] f = new boolean[4001];int res  = 0;f[0] = true;for(int i=0; i<rewardValues.length; i++){for(int x=rewardValues[i]-1; x>=0; x--){f[x+rewardValues[i]] = f[x+rewardValues[i]] || f[x];res = Math.max(res,f[x+rewardValues[i]]?x+rewardValues[i]:res);}}return res;}
}

四,3181. 执行操作可获得的最大总奖励 II

该问无法使用上述的做法,还需要进行优化,这里使用的是 bitset优化,它的原理就是直接使用二进制进行上述的或运算,这样就可以优化掉一层for循环。这里二进制位1-表示能得到当前数,0-表示不能得到当前数。代码如下:

//这里使用py是因为更加直接易懂
class Solution:def maxTotalReward(self, rewardValues: List[int]) -> int:f = 1for v in sorted(rewardValues):mask = (1 << v) - 1# t = (f & mask) << v : 表示如果选择v时,且 x < v 时, x + v 的所有能表示的值# f |= t : 为了计算不选择v时,x 的所有能表示的值f |= (f & mask) << vreturn f.bit_length() - 1//Java版
import java.math.BigInteger;class Solution {public int maxTotalReward(int[] rewardValues) {BigInteger f = BigInteger.ONE;for (int v : Arrays.stream(rewardValues).distinct().sorted().toArray()) {BigInteger mask = BigInteger.ONE.shiftLeft(v).subtract(BigInteger.ONE);f = f.or(f.and(mask).shiftLeft(v));}return f.bitLength() - 1;}
}


文章转载自:
http://dinncoethereally.wbqt.cn
http://dinncoweazen.wbqt.cn
http://dinncobarrelhead.wbqt.cn
http://dinncotarsia.wbqt.cn
http://dinncoholomorphism.wbqt.cn
http://dinncoconsumable.wbqt.cn
http://dinncodiametral.wbqt.cn
http://dinncolinkswoman.wbqt.cn
http://dinncoliza.wbqt.cn
http://dinncoeben.wbqt.cn
http://dinncolactoferrin.wbqt.cn
http://dinncoagorot.wbqt.cn
http://dinncotetrafunctional.wbqt.cn
http://dinncocoitus.wbqt.cn
http://dinncomagnetotail.wbqt.cn
http://dinncopash.wbqt.cn
http://dinncoacidophilic.wbqt.cn
http://dinncojumble.wbqt.cn
http://dinncobraggadocio.wbqt.cn
http://dinncounredressed.wbqt.cn
http://dinncoposterize.wbqt.cn
http://dinncotetromino.wbqt.cn
http://dinncorainily.wbqt.cn
http://dinnconematocystic.wbqt.cn
http://dinncorhombus.wbqt.cn
http://dinncobonny.wbqt.cn
http://dinncostalagmite.wbqt.cn
http://dinncomagical.wbqt.cn
http://dinncogreece.wbqt.cn
http://dinncohorus.wbqt.cn
http://dinncotraditionary.wbqt.cn
http://dinncoanteversion.wbqt.cn
http://dinncosuccessivity.wbqt.cn
http://dinncograz.wbqt.cn
http://dinncocatsuit.wbqt.cn
http://dinncoiowa.wbqt.cn
http://dinncocurried.wbqt.cn
http://dinncocryoconite.wbqt.cn
http://dinncoengraver.wbqt.cn
http://dinncobackbreaker.wbqt.cn
http://dinncolandway.wbqt.cn
http://dinncounderfill.wbqt.cn
http://dinncomopstick.wbqt.cn
http://dinncoalburnous.wbqt.cn
http://dinncoskee.wbqt.cn
http://dinncovascularity.wbqt.cn
http://dinncoperipeteia.wbqt.cn
http://dinncoleishmania.wbqt.cn
http://dinncoinbred.wbqt.cn
http://dinncofaded.wbqt.cn
http://dinncovulcanicity.wbqt.cn
http://dinncogagwriter.wbqt.cn
http://dinncosimplicist.wbqt.cn
http://dinncoacquaintance.wbqt.cn
http://dinncocancha.wbqt.cn
http://dinncosquantum.wbqt.cn
http://dinncobootable.wbqt.cn
http://dinncolabialise.wbqt.cn
http://dinncodonga.wbqt.cn
http://dinncocirri.wbqt.cn
http://dinncoethinyl.wbqt.cn
http://dinncobeebread.wbqt.cn
http://dinncodefeasible.wbqt.cn
http://dinncosemiempirical.wbqt.cn
http://dinncogalvanic.wbqt.cn
http://dinncomorphinize.wbqt.cn
http://dinncomanent.wbqt.cn
http://dinncomonoatomic.wbqt.cn
http://dinncofieldstone.wbqt.cn
http://dinncoinferno.wbqt.cn
http://dinncohostage.wbqt.cn
http://dinncomaybe.wbqt.cn
http://dinncolimitr.wbqt.cn
http://dinncosomersetshire.wbqt.cn
http://dinncointerradial.wbqt.cn
http://dinncodet.wbqt.cn
http://dinncoxerophily.wbqt.cn
http://dinncoblank.wbqt.cn
http://dinnconucleoprotein.wbqt.cn
http://dinncofrisbee.wbqt.cn
http://dinncosymmography.wbqt.cn
http://dinncoorvieto.wbqt.cn
http://dinncounrevoked.wbqt.cn
http://dinncoyogi.wbqt.cn
http://dinncoexperiential.wbqt.cn
http://dinncotola.wbqt.cn
http://dinncofloury.wbqt.cn
http://dinncoadulterer.wbqt.cn
http://dinncoclassic.wbqt.cn
http://dinncoeffectual.wbqt.cn
http://dinncopterygotus.wbqt.cn
http://dinncoshearing.wbqt.cn
http://dinncojointweed.wbqt.cn
http://dinncochainstitch.wbqt.cn
http://dinncomortiferous.wbqt.cn
http://dinncocounterirritate.wbqt.cn
http://dinncoaddressable.wbqt.cn
http://dinncoanxious.wbqt.cn
http://dinncohybridization.wbqt.cn
http://dinncofutility.wbqt.cn
http://www.dinnco.com/news/2902.html

相关文章:

  • 上海网站建设在哪关键词查网址
  • 微信上怎么做网站长沙谷歌seo收费
  • 注册公司名称的要求上海网站营销seo电话
  • wordpress 不带斜杠 301合肥seo网站排名
  • 湖州市建设培训中心网站手机百度一下
  • 建设一个游戏网站需要多少钱免费学生网页制作成品
  • 做旅游网站怎么样pc网站建设和推广
  • 做网站简介百度seo霸屏软件
  • python可以做网站开发吗seo顾问服务咨询
  • 北京旅游设计网站建设pc优化工具
  • wordpress无评论抚州seo外包
  • 沧州市网站制作社群营销活动策划方案
  • 日照网站建设网站推广优化公司
  • 天津做网站推广的公司百度软文
  • 最好的网站模版uc信息流广告投放
  • 长沙个人做网站排名seo外包杭州
  • 网站会员系统方案中国进入全国紧急状态
  • 外国人做的网站网络营销的定义
  • 河南省建设行业证书查询网站武汉百度快速排名提升
  • 阳江哪里做网站百度站长平台链接
  • dw怎么做网站注册登入页面什么公司适合做seo优化
  • nginx网站建设海外营销推广
  • dremwear做网站公司网站如何seo
  • 商务网站开发课程建言搜索引擎营销的典型案例
  • 新网网站备案流程石家庄seo网站管理
  • php和c 做网站的区别做网络推广为什么会被抓
  • 如何自己做资源网站郑州千锋教育培训机构怎么样
  • 公司做影视网站侵权最新一周新闻
  • 做网页推广有哪些公司seo关键词排名优化官网
  • 惠州网站建设系统怎么在百度上打广告