当前位置:网站首页>codeforces:D. Chip Move【dp + 逆向思维考虑】
codeforces:D. Chip Move【dp + 逆向思维考虑】
2022-08-05 19:50:00 【白速龙王的回眸】

分析
每个状态显然跟之前的有关系,所以用dp
我们可以知道如果每次取1倍,我们可以得到最多的步数,我们计算出最多的步数为tmp - 1
所以我们的步数可以是k到tmp - 1
顺着来的话,只能模拟超时
但如果倒着来,dp:只有tmp - 1, tmp - 2, tmp - t能去到的位置的次数
new_dp: 包括tmp - 1, tmp - 2, tmp - t, tmp - t - 1 >= k去到的位置的次数
那么我们在知道dp的前提下
new_dp[j] = new_dp[j - i] + dp[j - i]
因为当前的j,可以是当前新的tmp - t - 1得到的,也可以是旧的dp[j - i]时得到的
比较难想
ac code
import sys
from collections import defaultdict
input = sys.stdin.readline
MOD = 998244353
n, k = list(map(int, input().split()))
tmp = k
acc = k
while acc <= n:
tmp += 1
acc += tmp
dp = [0] * (n + 1)
#dp[tmp] = 1
#print(tmp, dp)
# 最大tmp - 1,从k开始
for i in range(tmp - 1, k - 1, -1):
# dp:只有tmp - 1, tmp - 2, tmp - t
# new_dp: 包括tmp - 1, tmp - 2, tmp - t, tmp - t - 1 >= k
new_dp = [0] * (n + 1)
new_dp[i] = 1
for j in range(i + 1, n + 1):
new_dp[j] = new_dp[j - i] + dp[j - i]
new_dp[j] %= MOD
dp = new_dp
#print(i, dp)
print(*dp[1:])
复杂度o^1.5
总结
正难则反
考虑最大步数
然后倒序dp
当前的newdp[j],由于我们必须把小的考虑进来,也就是i必须要参与
所以new_dp[j] = new_dp[j - i] + dp[j - i]
边栏推荐
猜你喜欢

The MVC design ideas

C language programming introduction to learn six steps, six steps to take you into the C language

C#中的DateTime类

Data arrives more than 1 day late

【开发者必看】【push kit】推送服务典型问题合集2

【AGC】开放式测试示例

云渲染掀起虚拟演唱会新热潮
![[Illustrated and textual] Detailed explanation of the method of one-click reinstallation of the Win11 system](/img/d4/8b64cec37e38e23bac60d646b8d909.png)
[Illustrated and textual] Detailed explanation of the method of one-click reinstallation of the Win11 system

解决ping: www.baidu.com: Name or service not known

第02篇:分布式负载均衡
随机推荐
Web接口资源是如何保存起来的?
不要小看一个Redis~ 从头到尾全是精华,阿里Redis速成笔记太香了
【ML】机器学习数据集:sklearn中回归数据集介绍
【StoneDB模块介绍】服务器模块
02 控制器《ThinkPHP6 入门到电商实战》
全志V853芯片在Tina下E907启动方式的选择
151. Reverse words in string - double pointer method
JDBC data persistence
方舟:生存进化开服服务器配置如何选择?
esp32 bluetooth手机蓝牙控制板子自带灯熄灭
leetcode-137.只出现一次的数字 II
MySQL get month and quarter
SwiftUI案例:尺寸自适应文本框
第03篇:SQL语法树解析
Good code in the eyes of compiler engineers (1): Loop Interchange
【Harmony OS】【FAQ】鸿蒙问题合集2
Swift 周报 第十期
编译器工程师眼中的好代码(1):Loop Interchange
falco 【1】规则
JVM参数配置说明