赞
踩
class
Exchange {
public
:
int
countWays(vector<
int
> penny,
int
n,
int
aim) {
if
(penny.empty()||n ==
0
)
return
0
;
vector<vector<
int
> > dp(n,vector<
int
>(aim+
1
));
for
(
int
i =
0
;i < n;i++) {
dp[i][
0
] =
1
;
}
for
(
int
j =
1
;j < aim+
1
;j++) {
dp[
0
][j] = j%penny[
0
] ==
0
?
1
:
0
;
}
for
(
int
i =
1
;i < n;i++) {
for
(
int
j =
1
;j < aim+
1
;j++) {
dp[i][j] = (j-penny[i]) >=
0
?(dp[i-
1
][j] + dp[i][j-penny[i]]):dp[i-
1
][j];
}
}
return
dp[n-
1
][aim];
}
};
class
Exchange {
public
:
int
countWays(vector<
int
> penny,
int
n,
int
aim) {
vector<
int
> dp(aim +
1
);
for
(
int
i =
0
; i <= aim; i++)
if
(i % penny[
0
] ==
0
)
dp[i] =
1
;
for
(
int
i =
1
; i < n; i++)
for
(
int
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。