-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12865.cpp
More file actions
46 lines (40 loc) · 861 Bytes
/
12865.cpp
File metadata and controls
46 lines (40 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef struct stuff
{
int w, v;
} S;
bool myfunction(stuff a, stuff b)
{
return a.w < b.w;
}
int dp[101][100001];
int main()
{
int N, K;
vector<stuff> stuffs;
scanf("%d %d", &N, &K);
for (int i = 0; i < N; i++)
{
stuff tmp;
scanf("%d %d", &tmp.w, &tmp.v);
stuffs.push_back(tmp);
}
sort(stuffs.begin(), stuffs.end(), myfunction);
for (int i = 1; i <= N; i++)
{
int weight = stuffs[i - 1].w;
int value = stuffs[i - 1].v;
for (int j = 0; j <= K; j++)
{
if (weight <= j)
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weight] + value);
else
dp[i][j] = dp[i - 1][j];
}
}
printf("%d\n", dp[N][K]);
return 0;
}