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

个人认为, 用数组标记的方法做此题更简单实用;

Posted by 117474335 at 2010-09-24 23:40:35 on Problem 1742
#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:
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