Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贡献一个dp思路(其实是dp+贪心)

Posted by jerryday at 2015-10-16 22:50:49 on Problem 1742
1800ms多,不是很快,不过核心思路很简单

dp[i][j] = 只使用前i种(包括第i种)coin达到value j时第i种coin最多剩多少个

if (dp[i-1][j] >= 0) 
    dp[i][j] = num[i];
else if (j >= val[i] && dp[i][j-val[i]] > 0)
    dp[i][j] = dp[i][j-val[i]] - 1;

不过这样二维数组会MLE,要优化成一维数组,复杂度仍然是O(mn)

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator