Leetcode 5274. 停在原地的方案数】的更多相关文章

纪念第一次正式参加,听说这次题目很水,感觉确实不是很难,一般前两题都很简单,这次,到第三题的时候,都还可以做,emm...... 实际代码记录: #include <iostream> #include <vector> #include <math.h> #include <string> #include <algorithm> using namespace std; /* * 功能:初始化m行n列的二维vector * 参数:m,n,ve…
[js]Leetcode每日一题-停在原地的方案数 [题目描述] 有一个长度为 arrLen 的数组,开始有一个指针在索引 0 处. 每一步操作中,你可以将指针向左或向右移动 1 步,或者停在原地(指针不能被移动到数组范围外). 给你两个整数 steps 和 arrLen ,请你计算并返回:在恰好执行 steps 次操作以后,指针仍然指向索引 0 处的方案数. 由于答案可能会很大,请返回方案数 模 10^9 + 7 后的结果. 示例1: 输入:steps = 3, arrLen = 2 输出:4…
题目描述: 自己的提交: class Solution: def numWays(self, steps: int, arrLen: int) -> int: l = min(steps,arrLen) dp = [0] * l dp[0] = 1 MOD = 10 ** 9 + 7 for step in range(steps): dp_ = dp[:] for i in range(len(dp)): if i == 0: dp_[i] = (dp[i] + dp[i+1]) % MOD…
题目链接:5274. 停在原地的方案数 You have a pointer at index 0 in an array of size arrLen. At each step, you can move 1 position to the left, 1 position to the right in the array or stay in the same place (The pointer should not be placed outside the array at any…
题目描述 “低价购买”这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:“低价购买:再低价购买”.每次你购买一支股票,你必须用低于你上次购买它的价格购买它.买的次数越多越好!你的目标是在遵循以上建议的前提下,求你最多能购买股票的次数.你将被给出一段时间内一支股票每天的出售价(2^16范围内的正整数),你可以选择在哪些天购买这支股票.每次购买都必须遵循“低价购买:再低价购买”的原则.写一个程序计算最大购买次数. 这里是某支股票的价格清单: 日期 1 2…
B. Appleman and Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are color…
题目描述 小明的花店新开张,为了吸引顾客,他想在花店的门口摆上一排花,共m盆.通过调查顾客的喜好,小明列出了顾客最喜欢的n种花,从1到n标号.为了在门口展出更多种花,规定第i种花不能超过ai盆,摆花时同一种花放在一起,且不同种类的花需按标号的从小到大的顺序依次摆列. 试编程计算,一共有多少种不同的摆花方案. 输入输出格式 输入格式: 第一行包含两个正整数n和m,中间用一个空格隔开. 第二行有n个整数,每两个整数之间用一个空格隔开,依次表示a1.a2.……an. 输出格式: 输出只有一行,一个整数…
题意:用13.23……k3这些数加起来组成n,输出总方案数 d(i, j)表示前i个数构成j的方案数则有 d(i, j) = d(i-1, j) + d(i, j - i3) 可以像01背包那样用滚动数组来实现 //#define LOCAL #include <iostream> #include <cstdio> #include <cstring> using namespace std; ; ]; int main(void) { #ifdef LOCAL fr…
[题目描述] 给出一个正整数序列 a,长度为 n,cyb 不喜欢完美,他要删掉一些数(也可以不删,即删掉0个),但是他不会乱删,他希望删去以后,能将 a 分成 2 个集合,使得两个非空集合的数的和相同,现在他希望你能帮他算出删数的方案数. [输入文件] 第一行 n 个正整数 以下有 n行,每行1个 正整数表示整数序列a [输出文件] 一个整数表示答案 [输入样例] 4 1 2 3 4 [输出样例] 3 [数据范围] 30%:n<=5 100%:n<=20 100%:a 中每个元素<=10…
Nim Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5545   Accepted: 2597 Description Nim is a 2-player game featuring several piles of stones. Players alternate turns, and on his/her turn, a player’s move consists of removing one or mor…