HDU 4791 Alice's Print Service 简单DP

连接:http://acm.hdu.edu.cn/showproblem.php?pid=4791

题意:打印问题,n次条件,打印量≥si时,每张纸的打印价格为pi(0≤n≤1e5),问打印m次询问,qi张时最少需要多少钱(0≤m≤1e5)。

思路:如果对每次询问进行便利复杂度O(m*n)太大,超时。所以进行离线处理,将询问排序,从小到大依次处理,处理过程O(n+m),但排序过程是O(mlogm),所以总体的复杂度还是O(mlogm)。

代码:

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define PI acos(-1.0)
#define maxn 100005
#define INF 0x7fffffff
#define eps 1e-8
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
struct aa
{
    LL p,s;
    LL cost;
} a[100005];
struct bb
{
    LL i,q;
    LL cost;
} b[100005];
bool cmp1(bb a,bb b)
{
    return a.i=0; i--)
            a[i].cost=min(a[i+1].cost,a[i].p*a[i].s);
        for(int i=0; i=a[top1].p&&top1


你可能感兴趣的:(DP)