题意比较简单,

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. MVC模式实现登录以及增删改查之登录(一)

    我在这里用的不是maven项目,用的一般的web项目,所以需要用到的架包需要自己去下载添加,在项目中,一定注意环境的配置,我用的是jre1.7 1  新建项目 2  建立好MVC的管理包,导入对应的架 ...

  2. Android -- 官方下拉刷新SwipeRefreshLayout

    V4的兼容包 API 大概就这4个常用的方法. code 布局 <RelativeLayout xmlns:android="http://schemas.android.com/ap ...

  3. 模板-->Matrix重载运算符:+,-,x

    如果有相应的OJ题目,欢迎同学们提供相应的链接 相关链接 所有模板的快速链接 poj_2118_Firepersons,my_ac_code 简单的测试 INPUT: 1 2 3 1 3 4 3 -1 ...

  4. ASP.NET图片验证码学习!

    1. 新建一个Validate.aspx,然后在Validate.aspx.cs编写代码: using System; using System.Collections; using System.C ...

  5. left ,right ,cross ,full/left outer join/区别 详解

    --创建测试表wwif OBJECT_ID('qq') is not null drop table qqcreate table qq([序号] varchar(5),[内容1] varchar(1 ...

  6. Ext4.1 grid 多选(可无checkbox)

    转载 在Ext4.1中的grid默认只能实现单选的. 如果你想要你的grid有多选功能,需要给grid增加selModel 如果你使用了Ext.create('Ext.selection.Checkb ...

  7. (转)echo和print的区别

    在实际使用中, print 和 echo 两者的功能几乎是完全一样.可以这么说,凡是有一个可以使用的地方,另一个也可以使用.但是,两者之间也还是一个非常重要的区别:在 echo 函数中,可以同时输出多 ...

  8. UIScrollView 之图片缩放

    UIScrollView 之图片缩放 有些时候,我们可能要对某些内容进行手势缩放,如下图所示 UIScrollView不仅能滚动显示大量内容,还能对其内容进行缩放处理 也就是说,要完成缩放功能的话,只 ...

  9. 开始Swift之旅 - HelloWorld

    //: Playground - noun: a place where people can play import UIKit var str = "Hello, playground& ...

  10. html5 的百度地图连接

    在一些网站上,我们经常会看到一些地址会有一个图标的形式展现,当你点击的时候就会加载一个你点击区域的地图出来,很神奇的一个功能,在之前是没有这样功能的,都是直接写上地址,你要去的话自己找去吧,现在有了这 ...