- 采药
- 2009-06-10 13:26:52 @
好难好难 真的好难
5 条评论
-
wuyifan LV 8 @ 2013-08-09 16:42:12
01背包
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int f[1002],c[102],w[102],n,v;
cin>>v>>n;
for(i=1;i<=n;i++) cin>>c[i]>>w[i];
for(int i=1;i<=n;i++){
for(j=v;j>=c[i];j--) f[j]=max(f[j],f[j-c[i]]+w[i]);
}
cout<<f[v]<<endl;
return 0;
} -
2009-06-11 20:13:35@
HEAT DP
DP太烦!
-
2009-06-11 17:30:45@
用DP不是更好些吗?
-
2009-06-10 21:33:27@
记忆搜直接AC
-
2009-06-10 15:44:57@
这么搜就能AC了
先按性价比排序在搜索,然后掐时就AC了。
program bag;
var
v,e:Array[0..1000] of longint;
i,j,k,n,m,T,ans,cut:longint;procedure swap(var a,b:longint);
var k:longint;
begin
k:=a; a:=b; b:=k;
end;procedure search(lev,T,tot:longint);
var i:longint;
begin
if tot+e[1]/v[1]*T10000000 then exit;
if lev=n+1 then
begin
if tot>ans then
ans:=tot;
exit;
end;
if v[lev]
- 1