https://vjudge.net/contest/353156#problem/A
一开始想着按背包做 = =
我的dp还是太菜了
应该按照单调序列做
1 #include <iostream> 2 #include <algorithm> 3 #include <vector> 4 using namespace std; 5 struct node{ 6 int l; 7 int s; 8 int v; 9 int ans; 10 node(){ 11 ans = 0; 12 } 13 }; 14 inline node newone(int a,int b,int c){ 15 node New; 16 New.l = max(a,b); 17 New.s = min(a,b); 18 New.v = c; 19 New.ans = New.v; 20 return New; 21 } 22 void init(vector<node>& vec,int n){ 23 int a,b,c; 24 for(int i = 0; i < n; i++){ 25 cin >> a >> b >> c; 26 vec.push_back(newone(a,b,c)); 27 vec.push_back(newone(a,c,b)); 28 vec.push_back(newone(c,b,a)); 29 } 30 } 31 32 bool comp(const node&a,const node&b){ 33 if(a.l != b.l)return a.l > b.l; 34 else return a.s > b.s; 35 } 36 int main(){ 37 int cnt = 1; 38 int n; 39 while(cin >> n && n){ 40 vector<node> vec; 41 init(vec,n); 42 sort(vec.begin(),vec.end(),comp); 43 int s = 3 * n - 1; 44 for(int i = s-1; i >= 0; i--){ 45 for(int j = i+1; j <= s; j++){ 46 if(vec[i].l > vec[j].l && vec[i].s > vec[j].s) 47 vec[i].ans = max(vec[i].ans,vec[j].ans + vec[i].v); 48 } 49 } 50 51 int ans = 0; 52 for(int i = 0; i <= s; i++) 53 ans = max(ans,vec[i].ans); 54 cout<<"Case "<<cnt++<<": maximum height = "<<ans<<endl; 55 } 56 return 0; 57 }
原文地址:https://www.cnblogs.com/popodynasty/p/12235705.html
时间: 2024-10-11 23:16:14