Maximum Sequence

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1797    Accepted Submission(s): 842

Problem Description
Steph is extremely obsessed with “sequence problems” that are usually seen on magazines: Given the sequence 11, 23, 30, 35, what is the next number? Steph always finds them too easy for such a genius like himself until one day Klay comes up with a problem and ask him about it.

Given two integer sequences {ai} and {bi} with the same length n, you are to find the next n numbers of {ai}: an+1…a2n

. Just like always, there are some restrictions on an+1…a2n

: for each number ai

, you must choose a number bk

from {bi}, and it must satisfy ai

≤max{aj

-j│bk

≤j<i}, and any bk

can’t be chosen more than once. Apparently, there are a great many possibilities, so you are required to find max{∑2nn+1ai

} modulo 109

+7 .

Now Steph finds it too hard to solve the problem, please help him.

 
Input
The input contains no more than 20 test cases.
For each test case, the first line consists of one integer n. The next line consists of n integers representing {ai}. And the third line consists of n integers representing {bi}.
1≤n≤250000, n≤a_i≤1500000, 1≤b_i≤n.
 
Output
For each test case, print the answer on one line: max{∑2nn+1ai

} modulo 109

+7。

 
Sample Input
4
8 11 8 5
3 1 4 2
 
Sample Output
27

分析可知 ,a_n+1-------a_2*n必定是一个非严格递减序列,由此可知对a_n+1-a_2*n有贡献的只可能是a_1-a_n+1(因为a_n+1-a_2*n是一个非严格递减序列)

所以首先预处理出来从每个A[i]起的贡献Max[i],然后加一起就可以了。(注意Max数组处理时没有管道a_n+1,所以要和a_n+1进行比较一下大小)
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
const int mod=1e9+;
int a[N],b[N],Max[N];
int main(){
   int n;
   while(scanf("%d",&n)!=EOF){
    for(int i=;i<=n;++i) scanf("%d",&a[i]),a[i]-=i;
    for(int i=;i<=n;++i) scanf("%d",&b[i]);
    Max[n]=a[n];
    for(int i=n-;i>=;--i) Max[i]=max(Max[i+],a[i]);
    sort(b+,b+n+);
    int ans1=Max[b[]]-n-,ans=Max[b[]];
    for(int i=;i<=n;++i)  ans=(ans+max(Max[b[i]],ans1))%mod;
    printf("%d\n",ans);
   }
}
 

HDU 6047 贪心思维题的更多相关文章

  1. hdu 4803 贪心/思维题

    http://acm.hdu.edu.cn/showproblem.php?pid=4803 话说C++还卡精度么?  G++  AC  C++ WA 我自己的贪心策略错了 -- 就是尽量下键,然后上 ...

  2. 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas

    题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...

  3. 贪心/思维题 UVA 11292 The Dragon of Loowater

    题目传送门 /* 题意:n个头,m个士兵,问能否砍掉n个头 贪心/思维题:两个数组升序排序,用最弱的士兵砍掉当前的头 */ #include <cstdio> #include <c ...

  4. ZOJ 3829 贪心 思维题

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...

  5. hdu 4091 数学思维题贪心

    /* 参看博客地址:http://blog.csdn.net/oceanlight/article/details/7857713 重点是取完最优的后剩余的rest=n%lcm+lcm;中性价比小的数 ...

  6. 【贪心 思维题】[USACO13MAR]扑克牌型Poker Hands

    看似区间数据结构的一道题 题目描述 Bessie and her friends are playing a unique version of poker involving a deck with ...

  7. HDU 5776 sum (思维题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5776 题目让你求是否有区间的和是m的倍数. 预处理前缀和,一旦有两个数模m的值相同,说明中间一部分连续 ...

  8. hdu 1009 贪心基础题

    B - 贪心 基础 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     64bi ...

  9. PAT 甲级 1067 Sort with Swap(0, i) (25 分)(贪心,思维题)*

    1067 Sort with Swap(0, i) (25 分)   Given any permutation of the numbers {0, 1, 2,..., N−1}, it is ea ...

随机推荐

  1. js 之 object

    js之object 对象 ECMA-262 把对象(object)定义为“属性的无序集合,每个属性存放一个原始值.对象或函数”.严格来说,这意味着对象是无特定顺序的值的数组. 尽管 ECMAScrip ...

  2. Burnside&Polya总结

    这里就算是一个小总结吧- 附参考的网址: http://blog.sina.com.cn/s/blog_6a46cc3f0100s2qf.html http://www.cnblogs.com/han ...

  3. 利用Mysqlbinlog恢复数据库数据

    关于binlog的详解请参考:http://zlyang.blog.51cto.com/1196234/1833062 binlog日志用于记录所有更新了数据或者已经潜在更新了数据的所有语句.语句以& ...

  4. nodejs操作MySQL,mysql连接池及事务的使用

    https://blog.csdn.net/jasnet_u/article/details/88605168

  5. Codeforces Round #622 (Div. 2) 1313 C1

    C1. Skyscrapers (easy version) time limit per test1 second memory limit per test512 megabytes inputs ...

  6. ACM-ICPC 2019 山东省省赛总结

    五题手快拿银,不然拿铜,甚至不拿,从结果上来看拿了铜牌对第一年的我们来说算好的,也不算太好. 从拿奖后的第一天,我想写这篇博客,但是我忍了下来,那时候被喜悦冲昏了头脑,当 冷静下来,我开始打算写这篇博 ...

  7. SQL 文件导入数据库

    1.首先通过 xshell 连接数据库服务器,执行命令 mysql -u root -p 命令,按照提示输入密码,连接上数据库 2.在连接终端上执行命令 create database JD_Mode ...

  8. python requests 接口测试

    1.get方法请求接口 url:显而易见,就是接口的地址url啦 headers:请求头,例如:content-type = application/x-www-form-urlencoded par ...

  9. muduo网络库源码学习————线程安全

    线程安全使用单例模式,保证了每次只创建单个对象,代码如下: Singleton.h // Use of this source code is governed by a BSD-style lice ...

  10. nginx代理vue项目

    很多项目的前端都使用vue编写的,在项目上线部署的时候,有些项目要求把前端页面和后台服务部署在不同的服务器,这就要求使用nginx代理,本文就来讲讲vue项目怎么使用nginx代理. 项目github ...