HDU 6047 贪心思维题

Posted Billyshuai

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU 6047 贪心思维题相关的知识,希望对你有一定的参考价值。

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+1a2n . Just like always, there are some restrictions on an+1a2n : 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=250008;
const int mod=1e9+7;
int a[N],b[N],Max[N];
int main(){
   int n;
   while(scanf("%d",&n)!=EOF){
    for(int i=1;i<=n;++i) scanf("%d",&a[i]),a[i]-=i;
    for(int i=1;i<=n;++i) scanf("%d",&b[i]);
    Max[n]=a[n];
    for(int i=n-1;i>=1;--i) Max[i]=max(Max[i+1],a[i]);
    sort(b+1,b+n+1);
    int ans1=Max[b[1]]-n-1,ans=Max[b[1]];
    for(int i=2;i<=n;++i)  ans=(ans+max(Max[b[i]],ans1))%mod;
    printf("%d\n",ans);
   }
}

 

 

以上是关于HDU 6047 贪心思维题的主要内容,如果未能解决你的问题,请参考以下文章

hdu 6047 Maximum Sequence(贪心)

HDU 6047 Maximum Sequence(贪心+线段树)

hdu_6047: Maximum Sequence (2017 多校第二场 1003)贪心

多校训练2HDU 6047 Maximum Sequence

杭电2018多校第一场(2018 Multi-University Training Contest 1) 1001.Maximum Multiple (HDU6298)-数学思维题(脑子是个好东西,

HDU - 6581 Vacation (贪心+思维+物理)