传送门

题目大意

给你n个物品,你有一个容量为W的背包,每一个物品都有它的重量和价值,让你从n个中选取若干个,使得总重量不超过背包的上限,而且使得价值最大。

分析

首先我们不难发现由于W很大,所以这并不是一个普通的01背包,但是我们发现由于所有的wi相差很小,所以如果按体积大小分类,所有物品将仅有4类,这样我们就可以枚举美类物品取了多少了,但是这样虽然时间复杂度没问题但空间会炸。于是我们用dpijk表示考虑到了第i个物品,共取了j个,这j个物品的体积和 - w1*j = k,这样我们就可以在满足复杂度的情况下得到总体积了。具体转移见代码。

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define sp cout<<"---------------------------------------------------"<<endl
int dp[][][],w[],v[];
int main(){
int n,m,i,j,k;
cin>>n>>m;
for(i=;i<=n;i++)
scanf("%d%d",&w[i],&v[i]);
for(i=;i<=n;i++)
for(j=;j<=i;j++)
for(k=;k<=*i;k++){
dp[i][j][k]=max(dp[i][j][k],dp[i-][j][k]);
if(k>=w[i]-w[])
dp[i][j][k]=max(dp[i][j][k],dp[i-][j-][k-(w[i]-w[])]+v[i]);
}
int ans=;
for(i=;i<=n;i++)
for(j=;j<=i*;j++)
if((long long)i*w[]+j<=(long long)m)
ans=max(ans,dp[n][i][j]);
cout<<ans<<endl;
return ;
}

ARC073D Simple Knapsack的更多相关文章

  1. Atcoder regular Contest 073(D - Simple Knapsack)

    Atcoder regular Contest 073(D - Simple Knapsack) 传送门 因为 w1≤wi≤w1+3 这个特殊条件,我们可以将每个重量离散化一下,同时多开一维记录选择的 ...

  2. 【AtCoder】ARC073

    ARC 073 C - Sentou 直接线段覆盖即可 #include <bits/stdc++.h> #define fi first #define se second #defin ...

  3. AtCoder Beginner Contest-060

    A - Shiritori Problem Statement You are given three strings A, B and C. Check whether they form a wo ...

  4. PHP设计模式(一)简单工厂模式 (Simple Factory For PHP)

    最近天气变化无常,身为程序猿的寡人!~终究难耐天气的挑战,病倒了,果然,程序猿还需多保养自己的身体,有句话这么说:一生只有两件事能报复你:不够努力的辜负和过度消耗身体的后患.话不多说,开始吧. 一.什 ...

  5. Design Patterns Simplified - Part 3 (Simple Factory)【设计模式简述--第三部分(简单工厂)】

    原文链接:http://www.c-sharpcorner.com/UploadFile/19b1bd/design-patterns-simplified-part3-factory/ Design ...

  6. WATERHAMMER: A COMPLEX PHENOMENON WITH A SIMPLE SOLUTION

    开启阅读模式 WATERHAMMER A COMPLEX PHENOMENON WITH A SIMPLE SOLUTION Waterhammer is an impact load that is ...

  7. BZOJ 3489: A simple rmq problem

    3489: A simple rmq problem Time Limit: 40 Sec  Memory Limit: 600 MBSubmit: 1594  Solved: 520[Submit] ...

  8. Le lié à la légèreté semblait être et donc plus simple

    Il est toutefois vraiment à partir www.runmasterfr.com/free-40-flyknit-2015-hommes-c-1_58_59.html de ...

  9. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

随机推荐

  1. 简单的说一下:tarits技法就是一种模板元编程,起可以将本来处于运行期的事拉到编译期来做,增加了运行效率。 看以非模板元编程的例子,就是前面的那个例子:

    void adance(std::list<int>::iterator& iter, int d) { if(typeid(std::iterator_traits<std ...

  2. hibernate ORM related

    一.单向关联(unidirectional associations): 1.1.1 Many-to-one Employee.hbm.xml <class name="Employe ...

  3. BEC listen and translation exercise 12

    More than 220 cities now have air quality monitoring systems and 42 others will have systems in plac ...

  4. uva11292 Dragon of Loowater(排序后贪心)

    #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #inc ...

  5. Python 3.5 socket OSError: [Errno 101] Network is unreachable

    /******************************************************************************** * Python 3.5 socke ...

  6. LeetCode 251. Flatten 2D Vector

    原题链接在这里:https://leetcode.com/problems/flatten-2d-vector/ 题目: Implement an iterator to flatten a 2d v ...

  7. Codeforces 808F. Card Game

    题目大意 一个物品有三个属性 : 价值,键值,等级. 你不能选取等级高于\(level\)的物品,键值之和为质数的两个数字不共存. 问最低的等级使得可以选出价值之和超过\(k\)的物品. \(n\le ...

  8. 清理svn.bat

     @echo on  color 2f  mode con: cols=80 lines=25  @REM  @echo 正在清理SVN文件,请稍候......  @rem 循环删除当前目录及子目录下 ...

  9. hl7 V2中Message Control ID的含义及应用

    HL7 v2中的MSH,MSA段都有Message Control ID. 有几点需要注意: 1.所有的MessageControlID必须唯一 2.对于MSH中的MessageControlID, ...

  10. linux下mysql配置文件my.cnf最详细解释

    MySQL配置文件在Windows下叫my.ini,在MySQL的安装根目录下:在Linux下叫my.cnf,该文件位于/etc/my.cnf. 可以查找下:find / -name my.cnf m ...