一、采药
01背包
d
p
[
i
+
u
[
j
]
]
=
m
a
x
(
d
p
[
i
]
+
v
[
j
]
)
dp[i+u[j]]=max(dp[i]+v[j])
dp[i+u[j]]=max(dp[i]+v[j])
二、开心的金明
同上
三、摆花
d p [ i ] [ j ] = ∑ k = i − a [ j ] i d p [ k ] [ j − 1 ] dp[i][j]=\sum_{k=i-a[j]}^{i} {dp[k][j-1]} dp[i][j]=∑k=i−a[j]idp[k][j−1]
四、守望者的逃离
(伪dp)
1.
d
p
[
i
]
=
d
p
[
i
−
1
]
+
60
,
m
−
=
10
(
m
≥
10
)
\ dp[i]=dp[i-1]+60,m-=10(m\geq10)
dp[i]=dp[i−1]+60,m−=10(m≥10)
d
p
[
i
]
=
d
p
[
i
−
1
]
,
m
+
=
4
(
m
<
10
)
\quad dp[i]=dp[i-1],m+=4(m<10)
dp[i]=dp[i−1],m+=4(m<10)
(贪心)
2.
d
p
[
i
]
=
m
a
x
(
d
p
[
i
]
,
d
p
[
i
−
1
]
+
17
)
dp[i]=max(dp[i],dp[i-1]+17)
dp[i]=max(dp[i],dp[i−1]+17)
五、石子合并
(区间dp)
d
p
[
i
]
[
j
]
=
m
a
x
/
m
i
n
(
d
p
[
i
]
[
k
]
+
d
p
[
k
]
[
j
]
+
w
[
i
]
[
j
]
)
(
i
≤
k
<
j
)
dp[i][j]=max/min(dp[i][k]+dp[k][j]+w[i][j])(i\leq k<j)
dp[i][j]=max/min(dp[i][k]+dp[k][j]+w[i][j])(i≤k<j)
六、能量项链
同上
七、花匠
(伪dp)
\划掉 QAQ
d
p
[
i
]
[
0
]
=
m
a
x
(
d
p
[
j
]
[
1
]
)
+
1
(
a
j
<
a
i
)
dp[i][0]=max(dp[j][1])+1(a_j<a_i)
dp[i][0]=max(dp[j][1])+1(aj<ai)
d
p
[
i
]
[
1
]
=
m
a
x
(
d
p
[
j
]
[
0
]
)
+
1
(
a
j
>
a
i
)
dp[i][1]=max(dp[j][0])+1(a_j>a_i)
dp[i][1]=max(dp[j][0])+1(aj>ai)
还在想这怕是要用数据结构维护,这黄题怎么这么蓝
正解:
dp[i][0]=(a[i-1]>a[i])?dp[i-1][1]+1:dp[i-1][0];
dp[i][1]=(a[i-1]<a[i])?dp[i-1][0]+1:dp[i-1][1];
八、飞翔的小鸟
d
p
[
i
]
[
j
]
=
m
i
n
(
d
p
[
i
−
1
]
[
j
−
p
∗
u
p
[
i
]
,
d
p
[
i
−
1
]
[
j
+
d
n
[
i
]
]
)
dp[i][j]=min(dp[i-1][j-p*up[i],dp[i-1][j+dn[i]])
dp[i][j]=min(dp[i−1][j−p∗up[i],dp[i−1][j+dn[i]])
若
不
存
在
d
p
[
i
]
[
j
]
!
=
I
N
F
(
l
[
i
]
<
j
<
r
[
i
]
)
,
死
若不存在dp[i][j]!=INF(l[i]<j<r[i]),死
若不存在dp[i][j]!=INF(l[i]<j<r[i]),死
O
(
n
3
)
O(n^3)
O(n3)挂
优化
p
∗
u
p
[
i
]
p*up[i]
p∗up[i](完全背包)
->
d
p
[
i
]
[
j
]
=
m
i
n
(
d
p
[
i
]
[
j
−
u
p
[
j
]
]
,
d
p
[
i
−
1
]
[
j
−
u
p
[
i
]
)
dp[i][j]=min(dp[i][j-up[j]],dp[i-1][j-up[i])
dp[i][j]=min(dp[i][j−up[j]],dp[i−1][j−up[i])
要拆开。。。
d
p
[
i
]
[
j
]
=
m
i
n
(
d
p
[
i
]
[
j
]
,
d
p
[
i
−
1
]
[
j
+
d
n
[
i
]
]
)
dp[i][j]=min(dp[i][j],dp[i-1][j+dn[i]])
dp[i][j]=min(dp[i][j],dp[i−1][j+dn[i]])