Skip to content

Commit 2bc7794

Browse files
authored
Create 2019-B-B.cpp
01 背包
1 parent f58db67 commit 2bc7794

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

Diff for: kick-start/2019-B-B.cpp

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include<bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
#define ms(x,v) memset(x,(v), sizeof(x))
6+
#define msn(x,v,n) memset(x,(v),sizeof(x[0]) * n)
7+
8+
#define INF 0x3f3f3f3f
9+
10+
typedef long long LL;
11+
12+
const int MAXN = 100 + 3;
13+
14+
int T;
15+
int n;
16+
17+
struct Node{
18+
LL s,l,e;
19+
};
20+
21+
Node stone[MAXN];
22+
23+
inline bool cmp(const Node& a,const Node& b){
24+
auto va = a.e + b.e - b.l * a.s;
25+
auto vb = a.e + b.e - a.l * b.s;
26+
return va > vb;
27+
}
28+
29+
LL dp[MAXN*MAXN];
30+
31+
32+
int main(int argc, char const *argv[])
33+
{
34+
ios :: sync_with_stdio(0);
35+
cin.tie(0);
36+
std::cout.precision(8);
37+
std::cout.setf( std::ios::fixed, std:: ios::floatfield );
38+
39+
cin >> T;
40+
41+
for(int t =1; t <= T ; ++t)
42+
{
43+
cin >> n ;
44+
for(int i=0 ; i< n ; ++i)
45+
cin >>stone[i].s >> stone[i].e >> stone[i].l;
46+
47+
sort(stone,stone+n,cmp);
48+
ms(dp,0);
49+
50+
int sum_time =0;
51+
for(int i=0 ; i<n ; ++i){
52+
sum_time += stone[i].s;
53+
for(LL time = sum_time ; time>=stone[i].s ; --time){
54+
auto value = stone[i].e - stone[i].l * (time - stone[i].s);
55+
if(value <=0)continue;
56+
dp[time] = max(dp[time],dp[time-stone[i].s] + value);
57+
}
58+
}
59+
cout << "Case #"<<t << ": " << *max_element(dp,dp+sum_time+1) << "\n";
60+
}
61+
62+
return 0;
63+
}

0 commit comments

Comments
 (0)