题意比较简单,

dp[i][j] 表示上一次男女吃的deliciousness分别为i, j的时候的吃的最多的苹果。

那么dp[i][j] = max(dp[i][k] + 1),   0 <  k <= j

dp[i][j] = max( max(dp[k][j]) + 1 ) , 0 < k <= i

对于第一个式子最大值 用树状数组线段树都可以解决, 第二个式子如果每次从0遍历到i再找最值的话,显然会超时。

仔细想想便可以发现第二个最值和第一个是一样的。 这个不好解释。 像是对称性那种 一样。

 #include <bits/stdc++.h>
using namespace std;
const int MAXN = ;
struct Node{
int h, d;
bool operator < (const Node &rhs)const{
return h != rhs.h ? h > rhs.h : d < rhs.d;
}
}apple[MAXN];
int arr[MAXN<<][MAXN<<];
int MAX;
inline int lowbit (int x){
return x & -x;
}
void Modify (int x, int y, int d){
while (y < MAX){
arr[x][y] = max(arr[x][y], d);
y += lowbit(y);
}
}
int query (int x, int y){
int res = ;
while (y){
res = max(arr[x][y], res);
y -= lowbit(y);
}
return res;
}
int lsh[MAXN << ], lshtot, tmp[MAXN << ];
int main()
{
int T, n;
scanf ("%d", &T);
while (T--){
scanf ("%d", &n);
lshtot = ;
for (int i = ; i < n; i++){
scanf ("%d%d", &apple[i].h, &apple[i].d);
lsh[lshtot++] = apple[i].d;
}
sort (apple, apple+n);
sort (lsh, lsh+lshtot);
lshtot = unique(lsh, lsh+lshtot) - lsh;
for (int i = ; i < n; i++){
apple[i].d = lower_bound(lsh, lsh+lshtot, apple[i].d) - lsh + ;
}
MAX = lshtot + ;
memset(arr, , sizeof (arr));
for (int i = ; i < n; i++){
for (int j = ; j <= lshtot+; j++){
tmp[j] = query(j, apple[i].d);
}
for (int j = ; j <= lshtot+; j++){
Modify(apple[i].d, j, tmp[j]+);
Modify(j, apple[i].d, tmp[j]+);
}
}
int ans = ;
for (int i = ; i <= lshtot+; i++){
ans = max(ans, query(i, lshtot+));
}
printf("%d\n", ans);
}
return ;
}

HDU5406---CRB and Apple( DP) 2015 Multi-University Training Contest 10的更多相关文章

  1. 2015 Multi-University Training Contest 10 hdu 5406 CRB and Apple

    CRB and Apple Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  2. 2015 Multi-University Training Contest 10(9/11)

    2015 Multi-University Training Contest 10 5406 CRB and Apple 1.排序之后费用流 spfa用stack才能过 //#pragma GCC o ...

  3. LightOJ 1033 Generating Palindromes(dp)

    LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  4. lightOJ 1047 Neighbor House (DP)

    lightOJ 1047   Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...

  5. UVA11125 - Arrange Some Marbles(dp)

    UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...

  6. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

  7. 初探动态规划(DP)

    学习qzz的命名,来写一篇关于动态规划(dp)的入门博客. 动态规划应该算是一个入门oier的坑,动态规划的抽象即神奇之处,让很多萌新 萌比. 写这篇博客的目标,就是想要用一些容易理解的方式,讲解入门 ...

  8. Tour(dp)

    Tour(dp) 给定平面上n(n<=1000)个点的坐标(按照x递增的顺序),各点x坐标不同,且均为正整数.请设计一条路线,从最左边的点出发,走到最右边的点后再返回,要求除了最左点和最右点之外 ...

  9. 2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP)

    .navbar-nav > li.active > a { background-image: none; background-color: #058; } .navbar-invers ...

随机推荐

  1. iOS 独立开发记录(上)

    个月前,完成了个人App的2.0版本,也在普天同庆的六一儿童节这天上架了.因为是个人开发,很多实现都是边探索边做.现在完成之后再回顾,发现自己走了些弯路.所以写了这篇总结,概览了从想法.设计.开发到最 ...

  2. discuz! X3.2 自定义后台门户模块模板里的标签

    这里只提供对源码的修改, 至于插件, 暂不考虑... 想在首页里展示一些自定义字段的内容, 奈何dz无此功能, 无奈去扒源码. 首先切到 source 文件夹下 1. 在 class/block/po ...

  3. 传感器 Sensor 加速度【示例】

    简介 坐标系 x轴:从左到右 y轴:从下到上 z轴:从内到外 这个坐标系与Android 2D API中的不同,传感器中的返回值都以此坐标系为准. SENSOR_TYPE_ACCELEROMETER  ...

  4. python文档字符串

    #coding=utf-8 #文档字符串def d(i,j): """这个函数实现了一个乘法运算. 函数会返回一个乘法运算的结果.""" k ...

  5. C#—集合(Collection)

    1.栈(stack<T>) using System; using System.Collections.Generic; using System.Linq; using System. ...

  6. .NET读取Excel

    1.代码 string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Path + ";Ext ...

  7. 二、T4模板

    上文带大家见识了下T4,这里呢开始介绍T4模板有关的内容.关于T4模板介绍和使用网上一搜一箩筐,想深入研究的可以自行去找些资料,这里只介绍接下来我们需要使用的一些知识,不会面面俱到的讲T4模板所有的知 ...

  8. iOS关于sqlite3操作

    原文:http://hi.baidu.com/clickto/blog/item/0c6904f787c34125720eec87.html iPhone中支持通过sqlite3来访问iPhone本地 ...

  9. iOS开发网络资源整理-持续更新

    本文记录iOS开发相关的网络社区和博客 1.objc中国 网址:http://objccn.io 简介:onevcat创建,项目的成立源于国内 Objective-C 社区对 objc.io 的翻译活 ...

  10. margin-top在IE与其他浏览器下的不同

    两个box,box1嵌套box2, box2使用margin-top在IE下与其他浏览器不同.待整理