#1340
Rucsac
Într-un magazin sunt n
obiecte; pentru fiecare se cunoaște greutatea G
și valoarea V
. Un hoț intră în magazin având un rucsac ce poate transporta o greutate maximă GMax
. El va fura anumite obiecte, sau porțiuni de obiecte, astfel încât suma greutăților obiectelor furate să nu depășească GMax
.
Să se stabilească câștigul maxim pe care îl poate obține hoțul. Câștigul este egal cu suma valorilor obiectelor furate. Câștigul adus de o fracțiune de obiect este direct proporțional cu greutatea fracțiunii.
Problema | Rucsac | Operații I/O | tastatură/ecran |
---|---|---|---|
Limita timp | 0.1 secunde | Limita memorie |
Total: 64 MB
/
Stivă 8 MB
|
Id soluție | #50100198 | Utilizator | |
Fișier | rucsac.cpp | Dimensiune | 891 B |
Data încărcării | 27 Martie 2024, 09:09 | Scor / rezultat | Eroare de compilare |
rucsac.cpp: In function 'void subm(int, int)': rucsac.cpp:6:11: error: 'n' was not declared in this scope if(K<=n) ^ rucsac.cpp:7:19: error: 'x' was not declared in this scope for(int i=x[k-1]+1; i<=n; ++i) ^ rucsac.cpp:7:21: error: 'k' was not declared in this scope for(int i=x[k-1]+1; i<=n; ++i) ^ rucsac.cpp:9:18: error: 'g' was not declared in this scope if(G+g[i]<=GMax) ^ rucsac.cpp:9:24: error: 'GMax' was not declared in this scope if(G+g[i]<=GMax) ^ rucsac.cpp:12:20: error: 'C' was not declared in this scope if(C+v[i]>CMax) ^ rucsac.cpp:12:22: error: 'v' was not declared in this scope if(C+v[i]>CMax) ^ rucsac.cpp:12:27: error: 'CMax' was not declared in this scope if(C+v[i]>CMax) ^ rucsac.cpp:16:17: error: 'CMax' was not declared in this scope CMax=C+v[i]; ^ rucsac.cpp:16:22: error: 'C' was not declared in this scope CMax=C+v[i]; ^ rucsac.cpp:16:24: error: 'v' was not declared in this scope CMax=C+v[i]; ^ rucsac.cpp:18:24: error: 'g' was not declared in this scope subm(k+1,G+g[i],c+cmax); ^ rucsac.cpp:18:29: error: 'c' was not declared in this scope subm(k+1,G+g[i],c+cmax); ^ rucsac.cpp:18:31: error: 'cmax' was not declared in this scope subm(k+1,G+g[i],c+cmax); ^ rucsac.cpp: In function 'int main()': rucsac.cpp:24:8: error: expected unqualified-id before '>>' token int>>n>>gmax; ^ rucsac.cpp:25:21: error: 'n' was not declared in this scope for(int i=1; i<=n; ++i) ^ rucsac.cpp:26:14: error: 'g' was not declared in this scope cin>>g[i]>>v[i]; ^ rucsac.cpp:26:20: error: 'v' was not declared in this scope cin>>g[i]>>v[i]; ^ rucsac.cpp:27:13: error: expected unqualified-id before ')' token for(int ) ^ rucsac.cpp:27:13: error: expected ';' before ')' token rucsac.cpp:27:13: error: expected primary-expression before ')' token rucsac.cpp:27:13: error: expected ';' before ')' token rucsac.cpp:28:19: error: 'gmax' was not declared in this scope for(int j=gmax-g[i]; j>=0; j--) ^ rucsac.cpp:28:24: error: 'g' was not declared in this scope for(int j=gmax-g[i]; j>=0; j--) ^ rucsac.cpp:28:26: error: 'i' was not declared in this scope for(int j=gmax-g[i]; j>=0; j--) ^ rucsac.cpp:29:13: error: 'vmax' was not declared in this scope vmax[G+g[i]]=max(Vmax[G+g[i],Vmax[G]+v[i]); ^ rucsac.cpp:29:18: error: 'G' was not declared in this scope vmax[G+g[i]]=max(Vmax[G+g[i],Vmax[G]+v[i]); ^ rucsac.cpp:29:30: error: 'Vmax' was not declared in this scope vmax[G+g[i]]=max(Vmax[G+g[i],Vmax[G]+v[i]); ^ rucsac.cpp:29:50: error: 'v' was not declared in this scope vmax[G+g[i]]=max(Vmax[G+g[i],Vmax[G]+v[i]); ^ rucsac.cpp:29:54: error: expected ']' before ')' token vmax[G+g[i]]=max(Vmax[G+g[i],Vmax[G]+v[i]); ^ rucsac.cpp:30:46: error: 'n' was not declared in this scope for(int i=1; i<=n; ++i) ^ rucsac.cpp:31:40: error: 'GMax' was not declared in this scope for(int G=GMax; G>=g[i]; --G) ^ rucsac.cpp:31:49: error: 'g' was not declared in this scope for(int G=GMax; G>=g[i]; --G) ^ rucsac.cpp:32:30: error: 'vmax' was not declared in this scope vmax[G]=max(vmax[G],vmax[G-g[i]]+v[i]); ^ rucsac.cpp:32:63: error: 'v' was not declared in this scope vmax[G]=max(vmax[G],vmax[G-g[i]]+v[i]); ^ rucsac.cpp:33:40: error: too many arguments to function 'void subm(int, int)' subm(1,0,0); ^ rucsac.cpp:4:6: note: declared here void subm(int K,int G) ^
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema Rucsac face parte din prima categorie. Soluția propusă de tine va fi evaluată astfel:
Suma punctajelor acordate pe testele utilizate pentru verificare este 100. Astfel, soluția ta poate obține cel mult 100 de puncte, caz în care se poate considera corectă.