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 |
个人认为, 用数组标记的方法做此题更简单实用;#include <stdio.h> int w[101], nu[101], n, m , e[100001], ans ; char f[100002] ; main () { int i, j, t ; while (scanf ("%d%d",&n, &m) , n | m){ ans = 0 ; for (i = 1; i <= n ; i ++ ) scanf ("%d", &w[i]) ; for (i = 1; i <= n; i ++ ) scanf ("%d", &nu[i]) ; memset (f, 0, 4 * (m + 1)) ; f[0] = 1 ; for (i = 1; i <= n ; i ++ ){ memset (e, 0, 4 * (m + 1)) ; for (j = w[i]; j <= m; j ++ ) if ( ! f[j] && f[j - w[i]] && e[j - w[i]] < nu[i]){ f[j] = 1 ; e[j] = e[j - w[i]] + 1; ans ++ ;}} printf ("%d\n", ans) ;} } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator