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. 大会聚焦 | 开源技术盛会LinuxCon首次来到中国,大咖齐聚关注业界动态

    2017年6月19-20日,开源技术盛会LinuxCon + ContainerCon + CloudOpen(LC3)首次在中国举行.两天议程满满,包括 17 个主旨演讲.8 个分会场的 88 场技 ...

  2. 一点对原生HTTP请求的理解与总结

    全手打原创,转载请标明出处:https://www.cnblogs.com/dreamsqin/p/10946165.html,多谢,=.=~ 术语 HTTP:超文本传输协议,规定Web浏览器如何从W ...

  3. POJ 1185 炮兵阵地 (状压DP,轮廓线DP)

    题意: 给一个n*m的矩阵,每个格子中有'P'或者'H',分别表示平地和高原,平地可以摆放大炮,而大炮的攻击范围在4个方向都是2格(除了自身位置),攻击范围内不能有其他炮,问最多能放多少个炮?(n&l ...

  4. Contour Features 边界特征

    查找轮廓 findContours   cv2.findContours(image, mode, method[, contours[, hierarchy[, offset]]]) → image ...

  5. fork新建进程

    #include <sys/types.h>#include<sys/wait.h>#include<unistd.h>#include<stdio.h> ...

  6. iBatis for net 框架使用

    简介:ibatis 一词来源于“internet”和“abatis”的组合,是一个由Clinton Begin在2001年发起的开放源代码项目,到后面发展的版本叫MyBatis但都是指的同一个东西.最 ...

  7. java ArrayList remove 2 及正确方法

    https://www.cnblogs.com/chrischennx/p/9610853.html 正确方式 方法一,还是fori,位置前挪了减回去就行了, remove后i--: public v ...

  8. TDB文件介绍

    samba在运行时,Samba 存储许多信息,从本地密码到希望从中收到信息的一系列客户端.这类数据其中一些是暂时的,在 Samba 重启时可能会被丢弃,但是另一些却是永久的,不会被丢弃.这类数据可能是 ...

  9. MySQL使用INSERT插入多条记录

    MySQL使用INSERT插入多条记录,应该如何操作呢?下面就为您详细介绍MySQL使用INSERT插入多条记录的实现方法,供您参考. 看到这个标题也许大家会问,这有什么好说的,调用多次INSERT语 ...

  10. cocos2dx for lua 加密图片

    图片加密的方法有很多种,在cocos2dx中,经常会使用TexturePacker来加密图片,方法如下: 打开TexturePacker,点击Add Sprite添加图片,在output栏下的Text ...