168 条题解
-
0martialmask LV 8 @ 2013-10-06 22:36:43
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
int V,W,N,f[410][410],vv[55],ww[55],cc[55];
int main()
{
scanf("%d%d%d",&V,&W,&N);
for(int i=1;i<=N;i++) cin>>vv[i]>>ww[i]>>cc[i];
for(int i=1;i<=N;i++)
for(int j=V;j>=vv[i];j--)
for(int k=W;k>=ww[i];k--)
if(f[j-vv[i]][k-ww[i]]+cc[i]>f[j][k])
f[j][k]=f[j-vv[i]][k-ww[i]]+cc[i];
cout<<f[V][W]<<endl;
return 0;
} -
02013-08-04 18:12:30@
果然刷水题有信心。。。。。O(∩_∩)O~
-
02013-03-31 19:56:11@
399+1,你的是错的
-
02010-07-09 11:03:34@
20留念
var
f:array[-1..401,-1..401] of longint;
v,m,n,i,j,k,a,b,c:longint;
begin
readln(v,m);
readln(n);
fillchar(f,sizeof(f),0);
for i:=1 to n do
begin
readln(a,b,c);
for j:=v downto 0 do
for k:=m downto 0 do
if j-a>=0 then
if k-b>=0 then
if f[j,k] -
02010-04-07 20:31:28@
AC111纪念
-
02009-11-09 10:29:16@
program P1334;
var
f:array[0..400,0..400]of longint;
vv,mm,u:array[1..50]of longint;
v,n,m,i,j,k:longint;begin
read(v,m,n);
for i:=1 to n do
readln(vv[i],mm[i],u[i]);
fillchar(f,sizeof(f),0);
for i:=1 to n do
for j:=v downto vv[i] do
if j-vv[i]>=0 then
for k:=m downto mm[i] do
if k-mm[i]>=0 then
if f[j-vv[i],k-mm[i]]+u[i]>f[j,k] then
f[j,k]:=f[j-vv[i],m-mm[i]]+u[i];writeln(f[v,m]);
end.
晕K打成了m,又降ac率!!!我的错 -
02009-11-09 08:09:38@
C语言版(古老的语言)
难度2有点高#include "stdio.h"
int V,M,BEST[401][401]={0};int max(int a,int b)
{
返回a,b中较大值
}void bag(int v,int m,int cal)
{
int i,j;
for(i=V;i>=v;i--)
for(j=M;j>=m;j--)
{
BEST[i][j]=max(BEST[i][j],BEST[j-m]+cal);
}
}int main()
{
int n,i,v,m,cal;
scanf("%d %d %d",&V,&M,&n);
for(i=0;i -
02009-11-04 18:38:59@
f表示前i个食品花费j的体积和k的质量能达到的最大卡路里值
显然f:=MAX(f,f+kaluli[i])Ans:=f[n,maxv,maxm]
显然可以压为二维的数组优化空间,但对于该题无需此举。
-
02009-10-29 14:03:19@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
├ 测试数据 06:答案正确... 0ms
├ 测试数据 07:答案正确... 0ms
├ 测试数据 08:答案正确... 0ms
├ 测试数据 09:答案正确... 0ms
├ 测试数据 10:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0msvar
a,b,c:array[0..100]of longint;
f:array[0..1000,0..1000]of longint;
n,v,m,i,j,k:longint;
begin
readln(v,m);
readln(n);
for i:=1 to n do
readln(a[i],b[i],c[i]);
for i:=1 to n do
for j:=v downto a[i] do
for k:=m downto b[i] do
if f[j,k] -
02009-10-15 20:30:49@
#include
using namespace std;
int f[51][401][401];
int main(void)
{
int i,j,k,w1,w2,n,p1[51],p2[51],v[51];
cin>>w1>>w2>>n;
for (i=1;i>p1[i]>>p2[i]>>v[i];
for (i=1;i -
02009-10-06 10:48:18@
第4001次提交,2星纪念
-
02009-09-27 21:48:04@
很水的题啊 还难度2
建议大家看看背包问题九讲 很有用
---|---|---|---|---|---|---|---|---|--晒程序---|---|---|---|---|---|---|---|---|---|-
program p1334;
var
a,b,c:array[0..100]of longint;
f:array[0..1000,0..1000]of longint;
n,v,m,i,j,k:longint;function max(a,b:longint):longint;
begin
if a>b then exit(a)
else exit(b);
end;begin
readln(v,m);
readln(n);
for i:=1 to n do
readln(a[i],b[i],c[i]);
for i:=1 to n do
for j:=v downto a[i] do
for k:=m downto b[i] do
f[j,k]:=max(f[j,k],f[j-a[i],k-b[i]]+c[i]);
writeln(f[v,m]);
end. -
02009-09-20 16:22:28@
难得一见的巨水题、、
-
02009-09-20 14:27:46@
var
i,j,k,x,y,z,n,maxv,maxm:longint;
f:array[0..400,0..400] of longint;
begin
readln(maxv,maxm);
readln(n);
for i:=1 to n do
begin
readln(x,y,z);
for j:=maxv downto x do
for k:=maxm downto y do
if f[j-x,k-y]+z>f[j,k] then
f[j,k]:=f[j-x,k-y]+z;
end;
writeln(f[maxv,maxm]);
end.
{var
worz,m,v,n,i,mi,vi:integer;
mm,vv,kk:array[1..50] of integer;
f:array[0..400,0..400] of integer;
begin
readln(v,m);
readln(n);
for i:=1 to n do
readln(vv[i],mm[i],kk[i]);
fillchar(f,sizeof(f),0);
for i:=1 to n do
for vi:=v downto vv[i] do
for mi:=m downto mm[i] do
if f[vi,mi] -
02009-09-06 16:30:33@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
├ 测试数据 06:答案正确... 0ms
├ 测试数据 07:答案正确... 0ms
├ 测试数据 08:答案正确... 0ms
├ 测试数据 09:答案正确... 0ms
├ 测试数据 10:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0ms
2维背包
2星纪念 -
02009-09-04 13:12:52@
var m,v,n,i,mi,vi:integer;
mm,vv,kk:array[1..50] of integer;
f:array[0..400,0..400] of integer;
begin
readln(v,m);
readln(n);
for i:=1 to n do readln(vv[i],mm[i],kk[i]);
fillchar(f,sizeof(f),0);
for i:=1 to n do
for vi:=v downto vv[i] do
for mi:=m downto mm[i] do
if f[vi,mi] -
02009-08-25 13:11:47@
背包
水题 -
02009-08-15 15:42:17@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
├ 测试数据 06:答案正确... 0ms
├ 测试数据 07:答案正确... 0ms
├ 测试数据 08:答案正确... 0ms
├ 测试数据 09:答案正确... 0ms
├ 测试数据 10:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0ms
program ex54;
var m,n,x,i,j,l:integer;
c,w,d:array[1..400]of integer;
f:array[0..50,0..400,0..400]of integer;function max(x,y:integer):integer;
begin
if x>y then max:=x
else max:=y;
end;begin
readln(m,l);
readln(n);
for i:=1 to n do readln(c[i],w[i],d[i]);
for i:=1 to n do
for x:=1 to m do
for j:=1 to l do
if (x>=c[i])and(j>=w[i]) then f:=max(f+d[i],f)
else f:=f;
writeln(f[n,m,l]);
readln;
end. -
02009-08-14 16:28:28@
var
k,maxw,maxm,n,i,j:longint;
w:array[0..50]of longint;
m:array[0..50]of longint;
ja:array[0..50]of longint;
f:array[0..400,0..400]of longint;
begin
readln(maxw,maxm);
readln(n);
for i:=1 to n do
readln(w[i],m[i],ja[i]);
for k:=1 to n do
for i:= maxw downto 1 do
for j:=maxm downto 1 do
if (i>=w[k])and(j>=m[k])and(f[i-w[k],j-m[k]]+ja[k]>f)
then
f:=f[i-w[k],j-m[k]]+ja[k];
writeln(f[maxw,maxm]);
end.
我发现假如不将物品带入f 那么..就要用downto ..
否则..用to -
02009-08-11 09:35:26@
15行秒杀,开到400就行了~滚动数组~
readln(v,m,z);
for i:=vmax downto v do
for j:=mmax downto m do
if f+z>f then
f:=f+z;