- 采药
- 2013-08-31 10:37:04 @
#include <iostream>
#include <cstdlib>
#include <stdio.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
long maxt,m,i,j;
long t[101],p[101];
long opt[200]={0};
using namespace std;
int main(int argc, char *argv[]) {
cin>>maxt;
cin>>m;
for(i=1;i<=m;i++){
cin>>t[i];
cin>>p[i];
}
for(i=1;i<=m;i++){
for(j=maxt;j>=t[i];j--){
if(opt[j-t[i]]+p[i]>opt[j]){
opt[j]=opt[j-t[i]]+p[i];
}
}
}
cout<<opt[maxt]<<endl;
}
2 条评论
-
盗板桥 LV 8 @ 2013-09-09 22:10:02
给你个装箱问题的代码,回去看看背包9讲
program p1133;
var v,num,i,j:longint;
c,f:array[1..20000]of longint;
function max(a,b:longint):longint;
begin
if a>=b then
exit(a);
exit(b);
end;
begin
readln(v);
readln(num);
for i:=1 to num do
readln(c[i]);
for i:=1 to num do
for j:=v downto c[i] do
if j>=c[i] then
f[j]:=max(f[j],f[j-c[i]]+c[i]);
writeln(v-f[v]);
end. -
2013-08-31 14:29:16@
呵呵,因为你写得不对
- 1