| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
!In Reply To:你们写代码都不写注释,这不是个好习惯,贴我的 Posted by:lafurose at 2017-04-15 11:31:37 #include<algorithm>
#include<iostream>
#include<cstdio>
using namespace std;
int N, M; //N个物品,包的体积为M
int w[3505], d[3505]; //体积,价值
int result[13005] = {0}; //result[i]表示从从 某些物品 中取出体积为i的最大价值
int main()
{
scanf("%d%d", &N, &M);
for (int i = 1; i <= N; ++i)
scanf("%d%d", &w[i], &d[i]);
for (int i = 1; i <= N; ++i) //从前i个物品取体积为j
for (int j = M; j >= w[i]; --j)
result[j] = max(result[j], result[j - w[i]] + d[i]);
printf("%d\n", result[M]);
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator