2018CCPC网络赛

J - YJJ's Salesman

HDU - 6447

YJJ is a salesman who has traveled through western country. YJJ is always on journey. Either is he at the destination, or on the way to destination. 
One day, he is going to travel from city A to southeastern city B. Let us assume that A is (0,0)(0,0) on the rectangle map and B (109,109)(109,109). YJJ is so busy so he never turn back or go twice the same way, he will only move to east, south or southeast, which means, if YJJ is at (x,y)(x,y) now (0≤x≤109,0≤y≤109)(0≤x≤109,0≤y≤109), he will only forward to (x+1,y)(x+1,y), (x,y+1)(x,y+1) or (x+1,y+1)(x+1,y+1). 
On the rectangle map from (0,0)(0,0) to (109,109)(109,109), there are several villages scattering on the map. Villagers will do business deals with salesmen from northwestern, but not northern or western. In mathematical language, this means when there is a village kk on (xk,yk)(xk,yk) (1≤xk≤109,1≤yk≤109)(1≤xk≤109,1≤yk≤109), only the one who was from (xk−1,yk−1)(xk−1,yk−1) to (xk,yk)(xk,yk) will be able to earn vkvk dollars.(YJJ may get different number of dollars from different village.) 
YJJ has no time to plan the path, can you help him to find maximum of dollars YJJ can get.

InputThe first line of the input contains an integer TT (1≤T≤10)(1≤T≤10),which is the number of test cases.

In each case, the first line of the input contains an integer NN (1≤N≤105)(1≤N≤105).The following NN lines, the kk-th line contains 3 integers, xk,yk,vkxk,yk,vk (0≤vk≤103)(0≤vk≤103), which indicate that there is a village on (xk,yk)(xk,yk) and he can get vkvk dollars in that village. 
The positions of each village is distinct.OutputThe maximum of dollars YJJ can get.Sample Input

1
3
1 1 1
1 2 2
3 3 1

Sample Output

3

就是现在有一个棋盘,你可以向右或者向下走,如果向右下的话就可以得到积分

dp方程就是这样dp[i][j] = max{dp[i-1][j],dp[i][j-1],dp[i-1][j-1]+v[i][j]},

可以用BIT去维护这个dp

但是点很多啊,也许又长又宽,但是能到的点和这个是无关的,所以可以离散化

为啥要离散化呢,因为有T组啊,但是放不离散化的代码AC就很不良心了吧

离散化可以先把y读入,并排序去除相同部分,所以每个的y都可以通过二分找到其位置并进行编号,所以根据其x和y和排序就可以进行了

每次找的过程都是在维护这个区间,dp[i]表示第到第a[i].y列的最大值,

因为我是排序了的,所以设置一个pos去更新的话,一定是t[pos].x<=t[i].x,所以我们在pos需要的地方更新,另外y已经被我们编号了,所以t[pos].y的值是可以去更新的,所以就做完了

#include <bits/stdc++.h>
using namespace std;
const int N=1e5+;
struct T
{
int x,y,v;
} t[N];
bool cmp(T a, T b)
{
return a.x<b.x;
}
int a[N],c[N];
int tot;
void update(int i, int val)
{
for(; i<=tot; i+=i&(-i))c[i]=max(c[i], val);
}
int query(int i)
{
int res=;
for(; i>; i-=i&(-i))res = max(res, c[i]);
return res;
}
int dp[N];
int main()
{
int T,n;
scanf("%d", &T);
while (T--)
{
scanf("%d", &n);
for(int i=; i<n; i++)scanf("%d%d%d",&t[i].x,&t[i].y,&t[i].v);
tot=,memset(c,,sizeof c);
for(int i=; i<n; i++)a[tot++]=t[i].y;
sort(a,a+tot);
tot=unique(a,a+tot)-a;
for(int i=; i<n; i++)t[i].y=lower_bound(a,a+tot,t[i].y)-a+;
sort(t,t+n,cmp);
for(int i=; i<n; i++) dp[i]=t[i].v;
int pos=,ans=;
for(int i=; i<n; i++)
{
while(pos<i&&t[pos].x!=t[i].x)update(t[pos].y,dp[pos]),pos++;
dp[i]=query(t[i].y-)+t[i].v,ans=max(ans,dp[i]);
}
printf("%d\n",ans);
}
return ;
}

BZOJ3594: [Scoi2014]方伯伯的玉米田

Time Limit: 60 Sec  Memory Limit: 128 MB
Submit: 1828  Solved: 873
[Submit][Status][Discuss]

Description

方伯伯在自己的农田边散步,他突然发现田里的一排玉米非常的不美。
这排玉米一共有N株,它们的高度参差不齐。
方伯伯认为单调不下降序列很美,所以他决定先把一些玉米拔高,再把破坏美感的玉米拔除掉,使得剩下的玉米的高度构成一个单调不下降序列。
方伯伯可以选择一个区间,把这个区间的玉米全部拔高1单位高度,他可以进行最多K次这样的操作。拔玉米则可以随意选择一个集合的玉米拔掉。
问能最多剩多少株玉米,来构成一排美丽的玉米。

Input

第1行包含2个整数n,K,分别表示这排玉米的数目以及最多可进行多少次操作。
第2行包含n个整数,第i个数表示这排玉米,从左到右第i株玉米的高度ai。

Output

输出1个整数,最多剩下的玉米数。

Sample Input

3 1
2 1 3

Sample Output

3

HINT

1 < N < 10000,1 < K ≤ 500,1 ≤ ai ≤5000

Source

By 佚名提供

数组可以选择k个区间+1,让这个最长不下降序列最长

f[i][j]表示前i个数,用j次区间+1的LIS长度

那我们可以考虑你最优的操作是什么,就是包含最后一个数字,所以可以倒着就行求解

#include<stdio.h>
#include<algorithm>
using namespace std;
int c[][];
int a[];
int query(int x,int y)
{
int ans=;
for(int i=x; i; i-=(i&(-i)))
for(int j=y; j; j-=(j&(-j)))
ans=max(ans,c[i][j]);
return ans;
}
inline void add(int x,int y,int val)
{
for(int i=x; i<; i+=(i&(-i)))
for(int j=y; j<; j+=(j&(-j)))
c[i][j]=max(c[i][j],val);
}
int main()
{
int n,m;
scanf("%d%d",&n,&m),m++;
for(int i=; i<=n; i++)scanf("%d",&a[i]);
int ans=;
for(int i=; i<=n; i++)
for(int j=m,t; j; j--)
{
t=query(a[i]+j,j)+,ans=max(ans,t);
add(a[i]+j,j,t);
}
printf("%d\n",ans);
}

BIT+DP的更多相关文章

  1. BZOJ 1911: [Apio2010]特别行动队 [斜率优化DP]

    1911: [Apio2010]特别行动队 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 4142  Solved: 1964[Submit][Statu ...

  2. 2013 Asia Changsha Regional Contest---Josephina and RPG(DP)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4800 Problem Description A role-playing game (RPG and ...

  3. AEAI DP V3.7.0 发布,开源综合应用开发平台

    1  升级说明 AEAI DP 3.7版本是AEAI DP一个里程碑版本,基于JDK1.7开发,在本版本中新增支持Rest服务开发机制(默认支持WebService服务开发机制),且支持WS服务.RS ...

  4. AEAI DP V3.6.0 升级说明,开源综合应用开发平台

    AEAI DP综合应用开发平台是一款扩展开发工具,专门用于开发MIS类的Java Web应用,本次发版的AEAI DP_v3.6.0版本为AEAI DP _v3.5.0版本的升级版本,该产品现已开源并 ...

  5. BZOJ 1597: [Usaco2008 Mar]土地购买 [斜率优化DP]

    1597: [Usaco2008 Mar]土地购买 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4026  Solved: 1473[Submit] ...

  6. [斜率优化DP]【学习笔记】【更新中】

    参考资料: 1.元旦集训的课件已经很好了 http://files.cnblogs.com/files/candy99/dp.pdf 2.http://www.cnblogs.com/MashiroS ...

  7. BZOJ 1010: [HNOI2008]玩具装箱toy [DP 斜率优化]

    1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 9812  Solved: 3978[Submit][St ...

  8. px、dp和sp,这些单位有什么区别?

    DP 这个是最常用但也最难理解的尺寸单位.它与“像素密度”密切相关,所以 首先我们解释一下什么是像素密度.假设有一部手机,屏幕的物理尺寸为1.5英寸x2英寸,屏幕分辨率为240x320,则我们可以计算 ...

  9. android px转换为dip/dp

    /** * 根据手机的分辨率从 dp 的单位 转成为 px(像素) */ public int dipTopx(Context context, float dpValue) { final floa ...

  10. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

随机推荐

  1. ThreadLocal的内存泄露

    ThreadLocal的目的就是为每一个使用ThreadLocal的线程都提供一个值,让该值和使用它的线程绑定,当然每一个线程都可以独立地改变它绑定的值.如果需要隔离多个线程之间的共享冲突,可以使用T ...

  2. python中的构造函数和构造函数和析构函数的作用

    构造函数和构造函数和析构函数都属于python中的特殊方法 其中的“__del__”就是一个析构函数了,当使用del 删除对象时,会调用他本身的析构函数,另外当对象在某个作用域中调用完毕,在跳出其作用 ...

  3. POJ Charm Bracelet 挑饰品 (常规01背包)

    问题:去珠宝店抢饰品,给出饰品种数n,能带走的重量m,以及每种饰品的重量w与价值v.求能带走的最大量. 思路:常规01背包. #include <iostream> using names ...

  4. 在Ubuntu12.04中搭建NFS的步骤

    1.首先安装nfs-kernel-server apt-get install nfs-kernel-server 2.然后创建一个目录: mkdir -p /opt/share 并赋予权限777: ...

  5. 组件的通信 :provide / inject 对象进入后,就等于不用props,然后内部对象,直接复制可以接受数组,属性不能直接复制,可以用Object.assgin覆盖对象,或者Vue的set 双向绑定数据

    组件的通信 :provide / inject 对象进入后,就等于不用props,然后内部对象,直接复制可以接受数组,属性不能直接复制,可以用Object.assgin覆盖对象,或者Vue的set 双 ...

  6. HTML5新增的音频标签、视频标签

    我们所说的H5就是我们所说的HTML5中新增的语言标准 一.音频标签 在HTML5当中有一个叫做audio的标签,可以直接引入一段音频资源放到我们的网页当中 格式: <audio autopla ...

  7. Sequence II

    6990: Sequence II 时间限制: 3 Sec  内存限制: 128 MB提交: 206  解决: 23[提交][状态][讨论版][命题人:admin] 题目描述 We define an ...

  8. 简单的邮件发送mail.jar

    public class MailSender { final static Logger logger = Logger.getLogger(MailSender.class); /** * 发送简 ...

  9. HTML DOM Frame 的 src

    定义和用法 src 属性可设置或返回应当被载入框架中的文档的 URL. 该属性只是 HTML 的 <frame> 标记的一个对应,并不是 Window.location 这样的 Locat ...

  10. 在Scrollview中使用AutoLayout

    AutoLayout 与 UIScrollView的相遇是一个不可避免的场景,像UITableView.UIWebView这些都是继承于UIScrollView的,关于它们的autolayout布局大 ...