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. 小白学phoneGap《构建跨平台APP:phoneGap移动应用实战》连载三(通过实例来体验生命周期)

    4.1.2  通过实例来亲身体验Activity的生命周期 上一小节介绍了Activity生命周期中的各个过程,本小节将以一个简单的实例来使读者亲身体验到Activity生命周期中的各个事件. 在Ec ...

  2. python3发送邮件02(简单例子,带附件)

    #!/usr/bin/env python# -*- coding:UTF-8 -*- import osimport smtplibfrom email.header import Headerfr ...

  3. javaSe数据类型

    在学完了java程序的结构以及注释后呢按照一般的教程我们应该学点什么呢?   没错就是变量和数据类型[其实我的内心是拒绝的,又是无聊的一大堆,不仅无聊,还得掌握] 好了首先介绍什么是变量: 变量:变量 ...

  4. Python使用easy-install安装时报UnicodeDecodeError的解决方法

    Python使用easy-install安装时报UnicodeDecodeError的解决方法,有需要的朋友可以参考下. 问题描述: 在使用easy-install安装matplotlib.pypar ...

  5. Spring Mybatis PageHelper 设置使用

    PageHelper是一个Mybatis的分页插件, 负责将已经写好的sql语句, 进行分页加工. 设置 现在使用的是PageHelper 5.0 版本 : 在build.gradle先引用jar包: ...

  6. CodeForces 66C Petya and File System (实现)

    模拟题,map搞一搞.要想清楚一个结点应该是要通过一个字符串找到下一个结点,题目保证所以文件夹非空,所以只要判断一个结点是不是叶子结点就可以判断它是不是文件,用了点c11的特性. #include&l ...

  7. [web开发] Vue+Spring Boot 上海大学预约系统开发记录

    前端界面 使用Quasar将组件都排好,用好css. Quasar 入门 # 确保你在全局安装了vue-cli # Node.js> = 8.9.0是必需的. $ npm install -g ...

  8. android上部署tensorflow

    https://www.jianshu.com/p/ddeb0400452f 按照这个博客就可以 https://github.com/CrystalChen1017/TSFOnAndroid 这个博 ...

  9. springboot 内置tomcat maxPostSizs 无法设置

    ++++++++++++++++++ RT +++++++++++++++++ 如下代码方可解决: /** * tomcat配置类 * 解决post数据体大于2048kb无法接收问题 * 解决tomc ...

  10. C#数组协方差

    对于任意两个“引用类型”A和B,如果存在从A到B的隐式引用转换或显式引用转换,则也一定存在从数组类型A[R]到数组类型B[R]的相同的引用转换,其中R可以是任何给定的“秩说明符”,但是这两个数组类型必 ...