HDU 6047 Maximum Sequence (贪心)
来源:互联网 发布:html5media.min.js 编辑:程序博客网 时间:2024/06/05 00:28
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 satisfyai≤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 findmax(∑2nn+1ai) modulo109+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≤ai≤1500000,1≤bi≤n
Output
For each test case, print the answer on one line:
max(∑2nn+1ai) modulo109+7 。
Sample Input
48 11 8 53 1 4 2
Sample Output
27
题意
给出数列
思路
题目很简单,但是题意好难懂。(可能是英语差的原因)
贪心思想,既然这样我们每次取
具体可以用两个优先队列来实现。
AC 代码
#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <vector>#include<queue>#include<iostream>using namespace std ;typedef __int64 LL;typedef pair<LL,int> P;const int mod = 1e9+7;int main(){ ios::sync_with_stdio(false); int n; while(cin>>n) { priority_queue<P>sk; priority_queue<int,vector<int>,greater<int> >b; LL ans=0; for(int i=1; i<=n; i++) { LL x; cin>>x; sk.push(P(x-i,i)); } for(int i=1; i<=n; i++) { int x; cin>>x; b.push(x); } for(int ti=n+1; !b.empty(); ti++) { int i=b.top(); b.pop(); while(sk.top().second<i) sk.pop(); P p=sk.top(); sk.push(P(p.first-ti,ti)); ans=(ans+p.first)%mod; } cout<<ans<<endl; } return 0;}
- HDU 6047 Maximum Sequence (贪心)
- HDU 6047 Maximum Sequence(贪心)
- HDU 6047 Maximum Sequence (贪心)
- hdu 6047Maximum Sequence(贪心)
- HDU 6047 Maximum Sequence【贪心】
- hdu 6047 Maximum Sequence (贪心)
- HDU 6047 Maximum Sequence (贪心,线段树)
- Hdu 6047 Maximum Sequence【贪心+优先队列】
- HDU 6047 Maximum Sequence 数论 贪心
- Maximum Sequence(hdu 6047)
- HDU 6047 Maximum Sequence 贪心 区间最值
- 2017 多校训练第二场 HDU 6047 Maximum Sequence(贪心+优先队列)
- [HDU]-6047 Maximum Sequence
- hdu 6047 Maximum Sequence
- [HDU 6047]Maximum Sequence
- HDU 6047 Maximum Sequence
- hdu 6047 Maximum Sequence
- HDU 6047 Maximum Sequence
- 杭电 OJ 1157
- 二叉树
- java项目几种常见数据库连接池的使用比较
- 数组的排序
- 【数据结构】链表的实现(带头节点)
- HDU 6047 Maximum Sequence (贪心)
- 第003讲:插曲之变量和字符串 ---学习笔记
- InfluxDB使用总结与性能优化
- HDU_【2017 Multi-University Training Contest 1】——1003 color tree
- 设计模式-单例模式
- 整数拆分 生成函数 模版
- 百度地图API使用——基础地图
- java.lang.IllegalArgumentException: Comparison method violates its general contract!
- hibernate 注解方式一对一 基于外键的形式