恩。。。一开始以为是二维树状数组随便搞。。。

后来看到数据范围额。。。

好吧,首先离散化x,按y排序,然后树状数组维护前缀和最大值即可。

(zky巨巨说是dp,那就算是dp好了,唔~)

离散化的时候偷懒用了map 233

 

 1 /**************************************************************
 2     Problem: 1537
 3     User: rausen
 4     Language: C++
 5     Result: Accepted
 6     Time:780 ms
 7     Memory:5412 kb
 8 ****************************************************************/
 9  
10 #include <cstdio>
11 #include <algorithm>
12 #include <map>
13  
14 #define lowbit(x) x & -x
15 using namespace std;
16 typedef map <int, int> Map;
17 typedef Map::iterator ITER;
18 const int N = 100005;
19  
20 struct point {
21     int x, y, v;
22     inline bool operator < (const point &b) const {
23         return y == b.y ? x < b.x : y < b.y;
24     }
25 } a[N];
26  
27 Map w;
28 int n, BIT[N], tot, ans;
29  
30 inline int read() {
31     int x = 0;
32     char ch = getchar();
33     while (ch < '0' || '9' < ch)
34         ch = getchar();
35     while ('0' <= ch && ch <= '9') {
36         x = x * 10 + ch - '0';
37         ch = getchar();
38     }
39     return x;
40 }
41  
42 inline void update(int x, int d) {
43     while (x <= n)
44         BIT[x] = max(BIT[x], d), x += lowbit(x);
45 }
46  
47 inline int query(int x) {
48     int res = 0;
49     while (x)
50         res = max(res, BIT[x]), x -= lowbit(x);
51     return res;
52 }
53  
54  
55 int main() {
56     int i, x;
57     ITER it;
58     read(), read(), n = read();
59     for (i = 1; i <= n; ++i) {
60         a[i].x = read(), a[i].y = read(), a[i].v = read();
61         w[a[i].x] = 1;
62     }
63     sort(a + 1, a + n + 1);
64     for (it = w.begin(); it != w.end(); ++it)
65         it -> second = ++tot;
66     for (i = 1; i <= n; ++i)
67         a[i].x = w[a[i].x];
68     for (i = 1; i <= n; ++i) {
69         x = query(a[i].x) + a[i].v;
70         update(a[i].x, x);
71         ans = max(ans, x);
72     }
73     printf("%d\n", ans);
74     return 0;
75 }
View Code

 

posted on 2014-11-30 10:57  Xs酱~  阅读(177)  评论(0编辑  收藏  举报