题目大意:
http://codevs.cn/problem/3027/
源码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <iostream> using namespace std; struct { int x,y,val; }tmp[1050]; int dp[1050] = {0}; int main() { int n; cin >> n ; for(int i = 1; i <= n; i++) { cin >> tmp[i].x >> tmp[i].y >> tmp[i].val; } tmp[0].x = tmp[0].y = tmp[0].val = 0; //排序方式很low啊,哈哈哈 for(int i = 1 ; i <= n; i++ ) { for(int j = i+1; j <= n; j++) { if(tmp[i].y > tmp[j].y) { int tmpx = tmp[i].x; int tmpy = tmp[i].y; int tmp_val = tmp[i].val; tmp[i].x = tmp[j].x; tmp[i].y = tmp[j].y; tmp[i].val = tmp[j].val; tmp[j].x = tmpx; tmp[j].y = tmpy; tmp[j].val = tmp_val; } } } dp[0] = 0; for(int i = 1; i <= n; i++) { for(int j = 0; j < i; j++) { if(tmp[i].x >= tmp[j].y) { dp[i] = max(dp[i-1], dp[j]+tmp[i].val); } } } cout << dp[n] << endl; return 0; }
这个排序方式很差啊,参考一下别人的:
结构体:
struct { int x,y,val; }tmp[1050];
排序:
#include<algorithm>
sort(tmp, tmp + n, comp);
函数:
int comp(tmp a, tmp b) { return a.y < b.y; }