多重背包(单调队列优化)

用单调队列可以大大提高效率

#include
#include
#define MAXN 105
struct Queue
{
    int num,value;
}que[250005];
int head,tail;
int v[MAXN],w[MAXN],c[MAXN];
int dp[250005];
void enqueue (int x,int y)
{
    while (head<=tail && que[tail].value=0)
    {
        sum=0;
        for (i=1 ; i<=n ; ++i)
        {
            scanf("%d%d",&v[i],&c[i]);
            w[i]=v[i];
            sum+=w[i]*c[i];
        }
        tempsum=sum;
        sum/=2;
        for (i=1 ; i<=sum ; ++i) dp[i]=0;
        for (i=1 ; i<=n ; ++i)
        {
            if (c[i] > sum/w[i]) c[i]=sum/w[i];
            for (d=0 ; d


你可能感兴趣的:(动态规划)