Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
贡献一个dp思路(其实是dp+贪心)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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator