Title Link: Http://codeforces.com/contest/837/problem/D
Test instructions: The number of K is selected in the N number, so that they have the most product at the end of 0.
Only need to count the number of 2 and 5 per number, one as capacity, one as value. F (i,k,j) indicates the number of first I selected K, altogether there are J 2 when, 5 up to a few.
The outer enumeration of the number of front I, the inner layer to do 01 backpack on it. But it will be mle, so scroll the array.
It is particularly important to note that scrolling arrays are copied when scrolling, because I did not copy them when I updated the 01 backpack ...
and F. Be aware that the current layer must be updated from the previous state, otherwise the state is wrong. By the way, it's too much trouble to write a map.
1#include <bits/stdc++.h>2 using namespacestd;3 4typedefLong LongLL;5 Const intMAXN =202;6 Const intMAXM = the*MAXN;7 intN, K;8 intf[2][MAXN][MAXM];9 intW2[MAXN], W5[MAXN], TOT[MAXN];Ten One signed Main () { A //freopen ("in", "R", stdin); - LL A; - while(~SCANF ("%d%d",&n,&K)) { theMemset (F,-1,sizeof(f)); -memset (Tot,0,sizeof(tot)); -memset (W2,0,sizeof(W2)); -memset (W5,0,sizeof(W5)); + for(inti =1; I <= N; i++) { -scanf"%lld", &a); + whileA5==0) w5[i]++, a/=5; A whileA2==0) w2[i]++, a/=2; atTot[i] = tot[i-1] +W2[i]; - } -f[0][0][0] =0; - intRET =0; - for(inti =1; I <= N; i++) { - for(intK =1; K <= K; k++) { in for(intj = Tot[i]; J >= W2[i]; j--) { -f[1][K][J] = max (f[1][K][J], f[0][k][j]); to if(f[0][k-1][j-w2[i]]! =-1) { +f[1][K][J] = max (f[0][k-1][j-w2[i]]+w5[i], f[1][k][j]); - } theRET = max (ret, Min (j, f[1][k][j])); * } $ }Panax Notoginseng for(intK =1; K <= K; k++) { - for(intj = maxm-1; J >=0; j--) { thef[0][K][J] = f[1][k][j]; + } A } the } +printf"%d\n", ret); - } $ return 0; $}
[cf837d] Round subset (scroll array, 01 backpack)