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. HTML JavaScript 基础(上)

    一.初识JavaScript JavaScript 和 Java什么关系? 半毛线关系都没有,只是名字有点重合而已. JavaScript 和python.C#.Java.Ruby一样,都是一门独立的 ...

  2. $_server[]关于浏览器和服务器的参数获取

    $_SERVER['USER'] www $_SERVER['HOME'] /home/www $_SERVER['HTTP_UPGRADE_INSECURE_REQUESTS'] 1 $_SERVE ...

  3. 信息竞赛进阶指南--Tire树

    // 假设字符串由小写字母构成 int trie[SIZE][26], tot = 1; // Trie的插入 void insert(char* str) { int len = strlen(st ...

  4. USACO Training Section 1.1 Your Ride Is Here

    题目描述 众所周知,在每一个彗星后都有一只UFO.这些UFO时常来收集地球上的忠诚支持者.不幸的是,他们的飞碟每次出行都只能带上一组支持者.因此,他们要用一种聪明的方案让这些小组提前知道谁会被彗星带走 ...

  5. FZU 1894 志愿者选拔

    Problem 1894 志愿者选拔 Accept: 2308 Submit: 7003 Time Limit: 1500 mSec Memory Limit : 32768 KB Problem D ...

  6. P3588 【[POI2015]PUS】(线段树优化建边)

    P3588 [[POI2015]PUS] 终于有个能让我一遍过的题了,写篇题解纪念一下 给定长度为n的序列和其中部分已知的数,还有m个大小关系:区间\([l,r]\)中,有k个给定的数比剩下的\(r- ...

  7. 自定义View实战

    PS:上一篇从0开始学自定义View有博友给我留言说要看实战,今天我特意写了几个例子,供大家参考,所画的图案加上动画看着确实让人舒服,喜欢的博友可以直接拿到自己的项目中去使用,由于我这个写的是demo ...

  8. jQuery简单竖排手风琴折叠菜单代码

    项目需求1.刚开始只显示,每个标题, 2.让每个 li列表隔行换色 3.当我点击某个标题时,下面的列表会缓慢的展开,其他列表展开的内容会收起 <!DOCTYPE html> <htm ...

  9. Spring Cloud学习 之 Spring Cloud Hystrix(流程分析)

    Spring Boot版本:2.1.4.RELEASE Spring Cloud版本:Greenwich.SR1 我们还是从流程图入手: 创建HystrixCommand或者HystrixObserv ...

  10. python3语法学习第四天--序列

    序列是Python中最基本的数据结构. 序列中的每个元素都分配一个索引从0开始依此类推. Python有6个序列的内置类型,但最常见的是列表和元组. 序列可以的操作:索引,切片,加,乘,检查成员. 此 ...