HDU 5808 Price List Strike Back

n 个物品,键值为为di,价值为 vi ,有 m 个询问,判断li ri 中键值不超过 ci 的物品能否组合出价值 sumi .
n2104,m105,1sumi,vi100,di,ci109

上古神犇Claris的题。

好像为了防止拆掉背包不是分块(CF 500F New Year Shopping)就是分治(本题)。

原来dp状态里只存能否达到(bitset?),然后按 di 从小到大更新背包。
价值 val 最多更新(r-l+1)个背包 100/val 次,乍一看还是很和谐的==>TLE。
正解dp状态里存的是,达成这个价值的最大键值最小是多少。

分治+背包dp

#include <set>
#include <ctime>
#include <queue>
#include <cstdio>
#include <bitset>
#include <cctype>
#include <bitset>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <iostream>
#include <algorithm>
#define inf (1<<30)
#define INF (1ll<<62)
#define fi first
#define se second
#define rep(x,s,t) for(register int x=s,t_=t;x<t_;++x)
#define per(x,s,t) for(register int x=t-1,s_=s;x>=s_;--x)
#define prt(x) cout<<#x<<":"<<x<<" "
#define prtn(x) cout<<#x<<":"<<x<<endl
#define pb(x) push_back(x)
#define hash asfmaljkg
#define rank asfjhgskjf
#define y1 asggnja
#define y2 slfvm
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
template<class T>void sc(T &x){
    int f=1;char c;x=0;
    while(c=getchar(),c<48)if(c=='-')f=-1;
    do x=x*10+(c^48);
    while(c=getchar(),c>47);
    x*=f;
}
template<class T>void nt(T x){
    if(!x)return;
    nt(x/10);
    putchar(x%10+'0');
}
template<class T>void pt(T x){
    if(x<0)putchar('-'),x=-x;
    if(!x)putchar('0');
    else nt(x);
}
template<class T>void ptn(T x){
    pt(x);putchar('\n');
}
template<class T>void pts(T x){
    pt(x);putchar(' ');
}
template<class T>inline void Max(T &x,T y){if(x<y)x=y;}
template<class T>inline void Min(T &x,T y){if(x>y)x=y;}

const int maxn=120006;
const int maxs=106;

int n,m;

struct node{
    int id,l,r,c,s;
    bool operator<(const node&a)const{
        if(c^a.c)return c<a.c;
        return id==-1;
    }
}d[maxn];

int dp[maxn][maxs];
int ans[maxn];
int a[maxn],b[maxn];

void pack(int *bag,int v,int c){
    per(i,0,101-v)
        if(bag[i]^inf)
            Min(bag[i+v],max(c,bag[i]));
}

void divide(int l,int r,int tot){
    if(!tot)return;
    if(l==r){
        rep(i,0,tot)ans[d[i].id]=(d[i].c<b[l]||(d[i].s^a[l]));
        return;
    }
    int mid=l+r>>1,nn;

    nn=0;
    rep(i,0,tot)if(d[i].r<=mid)swap(d[nn],d[i]),nn++;
    divide(l,mid,nn);

    nn=0;
    rep(i,0,tot)if(d[i].l>mid)swap(d[nn],d[i]),nn++;
    divide(mid+1,r,nn);

    nn=0;
    rep(i,0,tot)if(d[i].id==-1||(d[i].l<=mid&&d[i].r>mid))swap(d[nn],d[i]),nn++;

    rep(j,1,101)dp[mid][j]=dp[mid+1][j]=inf;
    dp[mid][a[mid]]=b[mid];
    dp[mid+1][a[mid+1]]=b[mid+1];
    per(i,l,mid){
        rep(j,1,101)dp[i][j]=dp[i+1][j];
        pack(dp[i],a[i],b[i]);
    }
    rep(i,mid+2,r+1){
        rep(j,1,101)dp[i][j]=dp[i-1][j];
        pack(dp[i],a[i],b[i]);
    }
    rep(i,0,nn){
        int id=d[i].id,lx=d[i].l,rx=d[i].r,s=d[i].s,c=d[i].c;
        ans[id]=1;
        rep(j,0,s+1){
            if(dp[lx][j]<=c&&dp[rx][s-j]<=c){
                ans[id]=0;
                break;
            }
        }
    }
}

void solve(){
    sc(n);sc(m);
    rep(i,1,n+1)sc(a[i]);
    rep(i,1,n+1)sc(b[i]);

    rep(i,0,m){
        d[i].id=i;
        sc(d[i].l);
        sc(d[i].r);
        sc(d[i].c);
        sc(d[i].s);
    }
    divide(1,n,m);
    rep(i,0,m)pt(ans[i]);
    putchar('\n');
}

int main(){
    int cas;sc(cas);
    while(cas--)solve();
    return 0;
}
智慧旅游解决方案利用云计算、物联网和移动互联网技术,通过便携终端设备,实现对旅游资源、经济、活动和旅游者信息的智能感知和发布。这种技术的应用旨在提升游客在旅游各个环节的体验,使他们能够轻松获取信息、规划行程、预订票务和安排食宿。智慧旅游平台为旅游管理部门、企业和游客提供服务,包括政策发布、行政管理、景区安全、游客流量统计分析、投诉反馈等。此外,平台还提供广告促销、库存信息、景点介绍、电子门票、社交互动等功能。 智慧旅游的建设规划得到了国家政策的支持,如《国家中长期科技发展规划纲要》和国务院的《关于加快发展旅游业的意见》,这些政策强调了旅游信息服务平台的建设和信息化服务的重要性。随着技术的成熟和政策环境的优化,智慧旅游的时机已经到来。 智慧旅游平台采用SaaS、PaaS和IaaS等云服务模式,提供简化的软件开发、测试和部署环境,实现资源的按需配置和快速部署。这些服务模式支持旅游企业、消费者和管理部门开发高性能、高可扩展的应用服务。平台还整合了旅游信息资源,提供了丰富的旅游产品创意平台和统一的旅游综合信息库。 智慧旅游融合应用面向游客和景区景点主管机构,提供无线城市门户、智能导游、智能门票及优惠券、景区综合安防、车辆及停车场管理等服务。这些应用通过物联网和云计算技术,实现了旅游服务的智能化、个性化和协同化,提高了旅游服务的自由度和信息共享的动态性。 智慧旅游的发展标志着旅游信息化建设的智能化和应用多样化趋势,多种技术和应用交叉渗透至旅游行业的各个方面,预示着全面的智慧旅游时代已经到来。智慧旅游不仅提升了游客的旅游体验,也为旅游管理和服务提供了高效的技术支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值