您的位置:首页 > 其它

poj 3624 01背包 (一维AC)

2012-05-04 16:29 295 查看
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#define Bug cout << "here\n";
using namespace std;
const int N = 3450;
int bag[12885];
int w
, v
;
int get_max(int a, int b) {
return a > b ? a : b;
}
int main() {
int i, k, n, m;
cin >> n >> m;
for(i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
memset(bag, 0, sizeof(bag));
for(i = 1; i <= n; i++) {
for(k = m; k >= w[i]; k--) {
bag[k] = get_max(bag[k], bag[k-w[i]] + v[i]);
}   /// bag[i][j] = get_min(bag[i-1][j], bag[i-1][j-w[i]]+v[i]);
}
cout << bag[m] << endl;
return 0;
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  include