题目描述
有一个箱子容量为VV(正整数,0 \le V \le 200000≤V≤20000),同时有nn个物品(0
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<list>
#include<iterator>
#include<stack>
#include <queue>
#include <cstdio>
//#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define e 2.718281828459
#define INF 0x7fffffff
#pragma warning(disable:4996)
#define sf scanf
#define pf printf
#define sf2d(x,y) scanf("%d %d",&(x),&(y))
#define sfd(x) scanf("%d",&x)
#define sff(p) scanf("%lf",&p)
#define pfd(x) printf("%d\n",x)
#define mset(x,b) memset((x),b,sizeof(x))
const double pi = acos(-1.0);
const long long mod = 1000000007LL;
int main()
{
int n, room;
int dp[20002];
int thing[31];
while (sfd(room) != EOF) {
sfd(n);
mset(dp, 0);
for (int i = 1; i <= n; i++)
sfd(thing[i]);
for (int i = 1; i <= n; i++) {
for (int j = room; j >= thing[i]; j--) {
dp[j] = max(dp[j], dp[j - thing[i]] + thing[i]);
}
}
pfd(room - dp[room]);
}
return 0;
}