#178. 「2019冬令营提高组」全连

显然我们可以得出一个$O(n^2)$的dp方程

记$f(i)$为取到第$i$个音符时的最大分数,枚举下一个音符的位置$j$进行转移。

蓝后我们就可以用树状数组存下$f(i)$的最大值,每次用$logn$的复杂度每次询问$j=1 \rightarrow i-t[i]$中最大$f(j)$值。

酱紫复杂度就变成了$O(nlogn)$

对于$f(i)$在位置$i+t[i]$之后才能作为转移的一个选择的问题,我们可以打一个延迟标记(ping函数),用类似链式前向星的结构存储(就像存边一样)。

每次到达一个$k$,就把每个从$k$开始起转移作用的$f(i)加入树状数组。

#include<cstdio>
typedef long long ll;
ll max(ll a,ll b){return a>b?a:b;}
void read(ll &x){
char c=getchar();x=;
while(c<''||c>'') c=getchar();
while(''<=c&&c<='') x=x*+(c^),c=getchar();
}
#define N 1000005
ll s[N],a[N],t[N],f[N],ans;
int n,cnt,hd[N],nxt[N],ed[N],poi[N];
void add(int x,ll v){for(;x<=n;x+=x&-x)s[x]=max(s[x],v);}
ll ask(int x){ll re=;for(;x;x-=x&-x)re=max(re,s[x]);return re;}
void ping(int x,int y){
nxt[ed[x]]=++cnt; hd[x]=hd[x]?hd[x]:cnt;
ed[x]=cnt; poi[cnt]=y;
}
int main(){
freopen("fc.in","r",stdin);
freopen("fc.out","w",stdout);
scanf("%d",&n);
for(int i=;i<=n;++i) read(t[i]);
for(int i=;i<=n;++i) read(a[i]);
for(int i=;i<=n;++i){
for(int j=hd[i];j;j=nxt[j]) add(poi[j],f[poi[j]]);//f[poi[j]]从i开始可以作为一个选择,加入树状数组
f[i]=a[i]*t[i];
if(i>t[i]) f[i]+=ask(i-t[i]);//查询1~i-t[i]的最优选择
if(i+t[i]<=n) ping(i+t[i],i);//把f(i)加入位置i+t[i]的标记中
ans=max(ans,f[i]);
}printf("%lld",ans);
return ;
}

fjwc2019 D1T1 全连(dp+树状数组)的更多相关文章

  1. 树形DP+树状数组 HDU 5877 Weak Pair

    //树形DP+树状数组 HDU 5877 Weak Pair // 思路:用树状数组每次加k/a[i],每个节点ans+=Sum(a[i]) 表示每次加大于等于a[i]的值 // 这道题要离散化 #i ...

  2. bzoj 1264 [AHOI2006]基因匹配Match(DP+树状数组)

    1264: [AHOI2006]基因匹配Match Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 793  Solved: 503[Submit][S ...

  3. 【bzoj2274】[Usaco2011 Feb]Generic Cow Protests dp+树状数组

    题目描述 Farmer John's N (1 <= N <= 100,000) cows are lined up in a row andnumbered 1..N. The cows ...

  4. 奶牛抗议 DP 树状数组

    奶牛抗议 DP 树状数组 USACO的题太猛了 容易想到\(DP\),设\(f[i]\)表示为在第\(i\)位时方案数,转移方程: \[ f[i]=\sum f[j]\;(j< i,sum[i] ...

  5. codeforces 597C C. Subsequences(dp+树状数组)

    题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standar ...

  6. HDU 2227 Find the nondecreasing subsequences (DP+树状数组+离散化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2227 Find the nondecreasing subsequences             ...

  7. ccpc_南阳 C The Battle of chibi dp + 树状数组

    题意:给你一个n个数的序列,要求从中找出含m个数的严格递增子序列,求能找出多少种不同的方案 dp[i][j]表示以第i个数结尾,形成的严格递增子序列长度为j的方案数 那么最终的答案应该就是sigma( ...

  8. HDU 2838 (DP+树状数组维护带权排序)

    Reference: http://blog.csdn.net/me4546/article/details/6333225 题目链接: http://acm.hdu.edu.cn/showprobl ...

  9. [poj3378] Crazy Thairs (DP + 树状数组维护 + 高精度)

    树状数组维护DP + 高精度 Description These days, Sempr is crazed on one problem named Crazy Thair. Given N (1 ...

随机推荐

  1. [Java] public, private, final and basic rules for naming.

    1. Access: public, private, protected public: Any other class can access a public field or method. ( ...

  2. Java Selenium - 浏览器操作

    浏览器主要操作方法来自接口 org.openqa.selenium.WebDriver , 实现于org.openqa.selenium.remote.RemoteWebDriver这个类,然后不同浏 ...

  3. Selenium基础知识(五)多窗口切换

    说到多窗口切换必须想到driver.switch_to.window()方法 driver.switch_to.window() 实现在不同窗口之间切换 driver.current_window_h ...

  4. python No tests were found问题解决方法

    由于刚刚开始用python去写测试接口框架,在写的过程中遇到No tests were found问题 原因:python中unittest框架是以Test开头的方法,所以定义方法或类不能以Test开 ...

  5. mybatis核心文件详解

    MyBatis配置文件详解 configuration  这是配置文件的根元素标签,所有的其他元素都要在这个标签下使用. environments   用于管理所有环境,并可以指定默认使用哪个环境,通 ...

  6. Hibernate框架第一天

    **框架和CRM项目的整体介绍** 1. 什么是CRM * CRM(Customer Relationship Management)客户关系管理,是利用相应的信息技术以及互联网技术来协调企业与顾客间 ...

  7. (转)Hashtable与ConcurrentHashMap区别

    ConcurrentHashMap融合了hashtable和hashmap二者的优势. hashtable是做了同步的,hashmap未考虑同步.所以hashmap在单线程情况下效率较高.hashta ...

  8. java中的锁之AbstractQueuedSynchronizer源码分析(二)

    一.成员变量. 1.目录. 2.state.该变量标记为volatile,说明该变量是对所有线程可见的.作用在于每个线程改变该值,都会马上让其他线程可见,在CAS(可见锁概念与锁优化)的时候是必不可少 ...

  9. WinSock学习笔记

    Socket(套接字)◆先看定义: typedef unsigned int u_int; typedef u_int SOCKET; ◆Socket相当于进行网络通信两端的插座,只要对方的Socke ...

  10. js函数集

    js函数集·字符串(String) 1.声明 var myString = new String("Every good boy does fine."); var myStrin ...