-
Notifications
You must be signed in to change notification settings - Fork 2
/
x.cpp
71 lines (54 loc) · 1.12 KB
/
x.cpp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 1e9 + 7;
ll int INF = 1e17;
struct Node {
Node(int weight, int solid, int val)
{
this->weight = weight;
this->solid = solid;
this->val = val;
}
int weight;
int solid;
int val;
};
vector <Node> arr;
ll int dp[1005][10005];
bool cmp(Node n1, Node n2)
{
if(n1.solid + n1.weight < n2.solid + n2.weight)
return true;
return false;
}
ll int kil(int idx, int weight)
{
if(weight >=10005)
return 0;
if(idx == arr.size())
return 0;
if(dp[idx][weight] != -1)
return dp[idx][weight];
dp[idx][weight] = 0;
dp[idx][weight] = max(dp[idx][weight], kil(idx+1, weight));
if(arr[idx].solid >= weight)
dp[idx][weight] = max(dp[idx][weight], kil(idx+1, weight + arr[idx].weight) + arr[idx].val);
return dp[idx][weight];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
memset(dp, -1, sizeof dp);
int n, x, y, z;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>x>>y>>z;
arr.push_back(Node(x, y, z));
}
sort(arr.begin(), arr.end(), cmp);
cout<<kil(0, 0)<<endl;
return 0;
}