Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
|
|
@ -12,17 +12,17 @@
|
|||
;; into vector of repeated indices : [1 2 3 4 4 4 5 5 6 ... ]
|
||||
|
||||
(define (make-01 T)
|
||||
(for ((record T) (i (in-naturals)))
|
||||
(for ((j (in-range 0 (goodies-qty record))))
|
||||
(vector-push IDX i)))
|
||||
IDX)
|
||||
|
||||
(for ((record T) (i (in-naturals)))
|
||||
(for ((j (in-range 0 (goodies-qty record))))
|
||||
(vector-push IDX i)))
|
||||
IDX)
|
||||
|
||||
(define-syntax-rule (name i) (table-xref T (vector-ref IDX i) 0))
|
||||
(define-syntax-rule (poids i) (table-xref T (vector-ref IDX i) 1))
|
||||
(define-syntax-rule (valeur i) (table-xref T (vector-ref IDX i) 2))
|
||||
|
||||
;;
|
||||
;; code identical to 0/1 problem
|
||||
;; code identical to 0/1 problem
|
||||
;;
|
||||
|
||||
;; make an unique hash-key from (i rest)
|
||||
|
|
@ -32,23 +32,23 @@
|
|||
|
||||
;; compute best score (i), assuming best (i-1 rest) is known
|
||||
(define (score i restant)
|
||||
(if (< i 0) 0
|
||||
(hash-ref! H (t-idx i restant)
|
||||
(if ( >= restant (poids i))
|
||||
(max
|
||||
(score (1- i) restant)
|
||||
(+ (score (1- i) (- restant (poids i))) (valeur i)))
|
||||
(score (1- i) restant)) ;; else not enough
|
||||
)))
|
||||
|
||||
(if (< i 0) 0
|
||||
(hash-ref! H (t-idx i restant)
|
||||
(if ( >= restant (poids i))
|
||||
(max
|
||||
(score (1- i) restant)
|
||||
(+ (score (1- i) (- restant (poids i))) (valeur i)))
|
||||
(score (1- i) restant)) ;; else not enough
|
||||
)))
|
||||
|
||||
;; compute best scores, starting from last item
|
||||
(define (task W)
|
||||
(define restant W)
|
||||
(make-01 T)
|
||||
(define N (1- (vector-length IDX)))
|
||||
(writeln 'total-value (score N W))
|
||||
(group
|
||||
(for/list ((i (in-range N -1 -1)))
|
||||
#:continue (= (t-get i restant) (t-get (1- i) restant))
|
||||
(set! restant (- restant (poids i)))
|
||||
(name i))))
|
||||
(writeln 'total-value (score N W))
|
||||
(group
|
||||
(for/list ((i (in-range N -1 -1)))
|
||||
#:continue (= (t-get i restant) (t-get (1- i) restant))
|
||||
(set! restant (- restant (poids i)))
|
||||
(name i))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue